Skip to content

Commit a836362

Browse files
committed
Issue python#28448: Fix C implemented asyncio.Future didn't work on Windows
1 parent 56b2cf5 commit a836362

File tree

8 files changed

+109
-8
lines changed

8 files changed

+109
-8
lines changed

Lib/asyncio/futures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ def cancel(self):
247247
if self._state != _PENDING:
248248
return False
249249
self._state = _CANCELLED
250-
self._schedule_callbacks()
250+
self.__schedule_callbacks()
251251
return True
252252

253-
def _schedule_callbacks(self):
253+
def __schedule_callbacks(self):
254254
"""Internal: Ask the event loop to call all callbacks.
255255
256256
The callbacks are scheduled to be called as soon as possible. Also
@@ -352,7 +352,7 @@ def set_result(self, result):
352352
raise InvalidStateError('{}: {!r}'.format(self._state, self))
353353
self._result = result
354354
self._state = _FINISHED
355-
self._schedule_callbacks()
355+
self.__schedule_callbacks()
356356

357357
def set_exception(self, exception):
358358
"""Mark the future done and set an exception.
@@ -369,7 +369,7 @@ def set_exception(self, exception):
369369
"and cannot be raised into a Future")
370370
self._exception = exception
371371
self._state = _FINISHED
372-
self._schedule_callbacks()
372+
self.__schedule_callbacks()
373373
if compat.PY34:
374374
self._log_traceback = True
375375
else:

Lib/asyncio/windows_events.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,13 @@ def __init__(self, ov, event, wait_handle, *, loop=None):
171171
def cancel(self):
172172
raise RuntimeError("_WaitCancelFuture must not be cancelled")
173173

174-
def _schedule_callbacks(self):
175-
super(_WaitCancelFuture, self)._schedule_callbacks()
174+
def set_result(self, result):
175+
super().set_result(result)
176+
if self._done_callback is not None:
177+
self._done_callback(self)
178+
179+
def set_exception(self, exception):
180+
super().set_exception(exception)
176181
if self._done_callback is not None:
177182
self._done_callback(self)
178183

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Core and Builtins
2020
Library
2121
-------
2222

23+
- Issue #28448: Fix C implemented asyncio.Future didn't work on Windows.
24+
2325
- Issue #28480: Fix error building socket module when multithreading is
2426
disabled.
2527

PCbuild/_asyncio.vcxproj

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|x64">
9+
<Configuration>Debug</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="PGInstrument|Win32">
13+
<Configuration>PGInstrument</Configuration>
14+
<Platform>Win32</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="PGInstrument|x64">
17+
<Configuration>PGInstrument</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
<ProjectConfiguration Include="PGUpdate|Win32">
21+
<Configuration>PGUpdate</Configuration>
22+
<Platform>Win32</Platform>
23+
</ProjectConfiguration>
24+
<ProjectConfiguration Include="PGUpdate|x64">
25+
<Configuration>PGUpdate</Configuration>
26+
<Platform>x64</Platform>
27+
</ProjectConfiguration>
28+
<ProjectConfiguration Include="Release|Win32">
29+
<Configuration>Release</Configuration>
30+
<Platform>Win32</Platform>
31+
</ProjectConfiguration>
32+
<ProjectConfiguration Include="Release|x64">
33+
<Configuration>Release</Configuration>
34+
<Platform>x64</Platform>
35+
</ProjectConfiguration>
36+
</ItemGroup>
37+
<PropertyGroup Label="Globals">
38+
<ProjectGuid>{384C224A-7474-476E-A01B-750EA7DE918C}</ProjectGuid>
39+
<RootNamespace>_asyncio</RootNamespace>
40+
<Keyword>Win32Proj</Keyword>
41+
</PropertyGroup>
42+
<Import Project="python.props" />
43+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
44+
<PropertyGroup Label="Configuration">
45+
<ConfigurationType>DynamicLibrary</ConfigurationType>
46+
<CharacterSet>NotSet</CharacterSet>
47+
</PropertyGroup>
48+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
49+
<PropertyGroup>
50+
<TargetExt>.pyd</TargetExt>
51+
</PropertyGroup>
52+
<ImportGroup Label="ExtensionSettings">
53+
</ImportGroup>
54+
<ImportGroup Label="PropertySheets">
55+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
56+
<Import Project="pyproject.props" />
57+
</ImportGroup>
58+
<PropertyGroup Label="UserMacros" />
59+
<PropertyGroup>
60+
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
61+
</PropertyGroup>
62+
<ItemGroup>
63+
<ClCompile Include="..\Modules\_asynciomodule.c" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<ResourceCompile Include="..\PC\python_nt.rc" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<ProjectReference Include="pythoncore.vcxproj">
70+
<Project>{cf7ac3d1-e2df-41d2-bea6-1e2556cdea26}</Project>
71+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
72+
</ProjectReference>
73+
</ItemGroup>
74+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
75+
<ImportGroup Label="ExtensionTargets">
76+
</ImportGroup>
77+
</Project>

PCbuild/_asyncio.vcxproj.filters

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<ResourceCompile Include="..\PC\python_nt.rc" />
5+
</ItemGroup>
6+
<ItemGroup>
7+
<Filter Include="Source Files">
8+
<UniqueIdentifier>{2422278e-eeeb-4241-8182-433e2bc5a7fc}</UniqueIdentifier>
9+
</Filter>
10+
</ItemGroup>
11+
<ItemGroup>
12+
<ClCompile Include="..\Modules\_asynciomodule.c">
13+
<Filter>Source Files</Filter>
14+
</ClCompile>
15+
</ItemGroup>
16+
</Project>

PCbuild/pcbuild.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<!-- _freeze_importlib -->
5252
<Projects Include="_freeze_importlib.vcxproj" />
5353
<!-- Extension modules -->
54-
<ExtensionModules Include="_ctypes;_decimal;_elementtree;_msi;_multiprocessing;_overlapped;pyexpat;select;unicodedata;winsound" />
54+
<ExtensionModules Include="_asyncio;_ctypes;_decimal;_elementtree;_msi;_multiprocessing;_overlapped;pyexpat;select;unicodedata;winsound" />
5555
<!-- Extension modules that require external sources -->
5656
<ExternalModules Include="_bz2;_lzma;_sqlite3" />
5757
<!-- _ssl will build _socket as well, which may cause conflicts in parallel builds -->

PCbuild/pcbuild.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pyshellext", "pyshellext.vc
9494
EndProject
9595
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_testconsole", "_testconsole.vcxproj", "{B244E787-C445-441C-BDF4-5A4F1A3A1E51}"
9696
EndProject
97+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_asyncio", "_asyncio.vcxproj", "{384C224A-7474-476E-A01B-750EA7DE918C}"
98+
EndProject
9799
Global
98100
GlobalSection(SolutionConfigurationPlatforms) = preSolution
99101
Debug|Win32 = Debug|Win32

PCbuild/pythoncore.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@
213213
<ClInclude Include="..\Python\wordcode_helpers.h" />
214214
</ItemGroup>
215215
<ItemGroup>
216-
<ClCompile Include="..\Modules\_asynciomodule.c" />
217216
<ClCompile Include="..\Modules\_bisectmodule.c" />
218217
<ClCompile Include="..\Modules\_blake2\blake2module.c" />
219218
<ClCompile Include="..\Modules\_blake2\blake2b_impl.c" />

0 commit comments

Comments
 (0)