bpo-37278: Fix test_asyncio ProactorLoopCtrlC (GH-14074)
Join the thread to prevent leaking a running thread and leaking a
reference.
Cleanup also the test:
* asyncioWindowsProactorEventLoopPolicy became the default policy,
there is no need to set it manually.
* Only start the thread once the loop is running.
* Use a shorter sleep in the thread (100 ms rather than 1 sec).
* Use close_loop(loop) rather than loop.close().
* Use longer variable names.
(cherry picked from commit 07559450b2
)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
This commit is contained in:
parent
7cd581a6bf
commit
8b66dbb212
|
@ -45,20 +45,21 @@ class ProactorLoopCtrlC(test_utils.TestCase):
|
||||||
def test_ctrl_c(self):
|
def test_ctrl_c(self):
|
||||||
|
|
||||||
def SIGINT_after_delay():
|
def SIGINT_after_delay():
|
||||||
time.sleep(1)
|
time.sleep(0.1)
|
||||||
signal.raise_signal(signal.SIGINT)
|
signal.raise_signal(signal.SIGINT)
|
||||||
|
|
||||||
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
|
thread = threading.Thread(target=SIGINT_after_delay)
|
||||||
l = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
try:
|
try:
|
||||||
t = threading.Thread(target=SIGINT_after_delay)
|
# only start the loop once the event loop is running
|
||||||
t.start()
|
loop.call_soon(thread.start)
|
||||||
l.run_forever()
|
loop.run_forever()
|
||||||
self.fail("should not fall through 'run_forever'")
|
self.fail("should not fall through 'run_forever'")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
l.close()
|
self.close_loop(loop)
|
||||||
|
thread.join()
|
||||||
|
|
||||||
|
|
||||||
class ProactorTests(test_utils.TestCase):
|
class ProactorTests(test_utils.TestCase):
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix test_asyncio ProactorLoopCtrlC: join the thread to prevent leaking a
|
||||||
|
running thread and leaking a reference.
|
Loading…
Reference in New Issue