diff options
| author | David Hewitt <1939362+davidhewitt@users.noreply.github.com> | 2022-04-25 16:56:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-25 08:56:20 -0700 |
| commit | 1cd8c29dace2dc6b91503803113fea4288ca842b (patch) | |
| tree | 96a36b51417054209edd83727b5bc7b1efdcd7f7 /Lib/test | |
| parent | 54d068adfbf2b822bcbf90dac9b3f6684cec0f99 (diff) | |
| download | cpython-git-1cd8c29dace2dc6b91503803113fea4288ca842b.tar.gz | |
gh-91880: add try/except around `signal.signal` (#91881)
Fixes gh-91880.
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_asyncio/test_runners.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_runners.py b/Lib/test/test_asyncio/test_runners.py index 42aa07a0e0..0c20921478 100644 --- a/Lib/test/test_asyncio/test_runners.py +++ b/Lib/test/test_asyncio/test_runners.py @@ -3,10 +3,12 @@ import asyncio import contextvars import gc import re +import signal import threading import unittest from unittest import mock +from unittest.mock import patch from test.test_asyncio import utils as test_utils @@ -374,6 +376,23 @@ class RunnerTests(BaseTest): with asyncio.Runner() as runner: with self.assertRaises(asyncio.CancelledError): runner.run(coro()) + + def test_signal_install_not_supported_ok(self): + # signal.signal() can throw if the "main thread" doensn't have signals enabled + assert threading.current_thread() is threading.main_thread() + + async def coro(): + pass + + with asyncio.Runner() as runner: + with patch.object( + signal, + "signal", + side_effect=ValueError( + "signal only works in main thread of the main interpreter" + ) + ): + runner.run(coro()) if __name__ == '__main__': |
