Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/asyncio/windows_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,12 @@ def run_forever(self):
super().run_forever()
finally:
if self._self_reading_future is not None:
ov = self._self_reading_future._ov
self._self_reading_future.cancel()
# self_reading_future was just cancelled so it will never be signalled
# Unregister it otherwise IocpProactor.close will wait for it forever
if ov is not None:
self._proactor._unregister(ov)
self._self_reading_future = None

async def create_pipe_connection(self, protocol_factory, address):
Expand Down
63 changes: 0 additions & 63 deletions Lib/test/test_asyncio/test_ctrl_c_in_proactor_loop_helper.py

This file was deleted.

32 changes: 19 additions & 13 deletions Lib/test/test_asyncio/test_windows_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import sys
import subprocess
import time
import threading
import unittest
from unittest import mock

if sys.platform != 'win32':
raise unittest.SkipTest('Windows only')

import _overlapped
import _testcapi
import _winapi

import asyncio
Expand Down Expand Up @@ -38,20 +40,24 @@ def data_received(self, data):


class ProactorLoopCtrlC(test_utils.TestCase):

def test_ctrl_c(self):
from .test_ctrl_c_in_proactor_loop_helper import __file__ as f

# ctrl-c will be sent to all processes that share the same console
# in order to isolate the effect of raising ctrl-c we'll create
# a process with a new console
flags = subprocess.CREATE_NEW_CONSOLE
with spawn_python(f, creationflags=flags) as p:
try:
exit_code = p.wait(timeout=5)
self.assertEqual(exit_code, 255)
except:
p.kill()
raise

def SIGINT_after_delay():
time.sleep(1)
_testcapi.raise_signal(signal.SIGINT)

asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
l = asyncio.get_event_loop()
try:
t = threading.Thread(target=SIGINT_after_delay)
t.start()
l.run_forever()
self.fail("should not fall through 'run_forever'")
except KeyboardInterrupt:
pass
finally:
l.close()


class ProactorTests(test_utils.TestCase):
Expand Down