Skip to content

Commit 2ed0e62

Browse files
committed
merge more things from winloop on over to uvloop in test_signals
1 parent 7fb3f43 commit 2ed0e62

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

tests/test_signals.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import os
23
import signal
34
import subprocess
45
import sys
@@ -304,10 +305,17 @@ def test_signals_invalid_signal(self):
304305
self.loop.add_signal_handler(signal.SIGKILL, lambda *a: None)
305306

306307
def test_signals_coro_callback(self):
308+
if sys.platform == "win32" and self.NEW_LOOP == "asyncio.new_event_loop()":
309+
raise unittest.SkipTest("no add_signal_handler on asyncio loop on Windows")
310+
307311
async def coro():
308312
pass
309313
with self.assertRaisesRegex(TypeError, 'coroutines cannot be used'):
310-
self.loop.add_signal_handler(signal.SIGHUP, coro)
314+
if sys.platform == "win32":
315+
# Winloop comment: use (arbitrary) signal defined on Windows
316+
self.loop.add_signal_handler(signal.SIGILL, coro)
317+
else:
318+
self.loop.add_signal_handler(signal.SIGHUP, coro)
311319

312320
def test_signals_wakeup_fd_unchanged(self):
313321
async def runner():
@@ -382,10 +390,28 @@ def run():
382390
383391
run()
384392
"""
393+
# Winloop comment: in PROG above we use default setting
394+
# for start_method: on Linux 'fork' and on Windows 'spawn'.
395+
# Also, avoid call run() during import.
396+
if sys.platform != "win32":
385397

386-
subprocess.check_call([
398+
subprocess.check_call([
387399
sys.executable, b'-W', b'ignore', b'-c', PROG,
388-
])
400+
])
401+
else:
402+
# Winloop comment: spawn uses pickle on subprocess()
403+
# but this gives an error like:
404+
# "... self = reduction.pickle.load(from_parent)
405+
# AttributeError: Can't get attribute 'subprocess'
406+
# on <module '__main__' (built-in)>"
407+
# Therefore we run PROG as a script.
408+
with open("tempfiletstsig.py", "wt") as f:
409+
f.write(PROG)
410+
subprocess.check_call(
411+
[sys.executable, b"-W", b"ignore", b"tempfiletstsig.py"]
412+
)
413+
os.remove("tempfiletstsig.py")
414+
389415

390416

391417
class Test_UV_Signals(_TestSignal, tb.UVTestCase):

0 commit comments

Comments
 (0)