|
1 | 1 | import asyncio |
| 2 | +import os |
2 | 3 | import signal |
3 | 4 | import subprocess |
4 | 5 | import sys |
@@ -304,10 +305,17 @@ def test_signals_invalid_signal(self): |
304 | 305 | self.loop.add_signal_handler(signal.SIGKILL, lambda *a: None) |
305 | 306 |
|
306 | 307 | 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 | + |
307 | 311 | async def coro(): |
308 | 312 | pass |
309 | 313 | 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) |
311 | 319 |
|
312 | 320 | def test_signals_wakeup_fd_unchanged(self): |
313 | 321 | async def runner(): |
@@ -382,10 +390,28 @@ def run(): |
382 | 390 |
|
383 | 391 | run() |
384 | 392 | """ |
| 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": |
385 | 397 |
|
386 | | - subprocess.check_call([ |
| 398 | + subprocess.check_call([ |
387 | 399 | 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 | + |
389 | 415 |
|
390 | 416 |
|
391 | 417 | class Test_UV_Signals(_TestSignal, tb.UVTestCase): |
|
0 commit comments