forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpo-23057: add loop self socket as wakeup fd for signals (python#11135)
- Loading branch information
Showing
6 changed files
with
104 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
Lib/test/test_asyncio/test_ctrl_c_in_proactor_loop_helper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import sys | ||
|
||
|
||
def do_in_child_process(): | ||
import asyncio | ||
|
||
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy()) | ||
l = asyncio.get_event_loop() | ||
|
||
def step(n): | ||
try: | ||
print(n) | ||
sys.stdout.flush() | ||
l.run_forever() | ||
sys.exit(100) | ||
except KeyboardInterrupt: | ||
# ok | ||
pass | ||
except: | ||
# error - use default exit code | ||
sys.exit(200) | ||
|
||
step(1) | ||
step(2) | ||
sys.exit(255) | ||
|
||
|
||
def do_in_main_process(): | ||
import os | ||
import signal | ||
import subprocess | ||
import time | ||
from test.support.script_helper import spawn_python | ||
|
||
ok = False | ||
|
||
def step(p, expected): | ||
s = p.stdout.readline() | ||
if s != expected: | ||
raise Exception(f"Unexpected line: got {s}, expected '{expected}'") | ||
# ensure that child process gets to run_forever | ||
time.sleep(0.5) | ||
os.kill(p.pid, signal.CTRL_C_EVENT) | ||
|
||
with spawn_python(__file__, "--child") as p: | ||
try: | ||
# ignore ctrl-c in current process | ||
signal.signal(signal.SIGINT, signal.SIG_IGN) | ||
step(p, b"1\r\n") | ||
step(p, b"2\r\n") | ||
exit_code = p.wait(timeout=5) | ||
ok = exit_code = 255 | ||
except Exception as e: | ||
sys.stderr.write(repr(e)) | ||
p.kill() | ||
sys.exit(255 if ok else 1) | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) == 1: | ||
do_in_main_process() | ||
else: | ||
do_in_child_process() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2018-12-12-16-24-55.bpo-23057.OB4Z1Y.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Unblock Proactor event loop when keyboard interrupt is received on Windows |