MCPcopy Index your code
hub / github.com/python/cpython / test_create_daemon_thread

Method test_create_daemon_thread

Lib/test/test__interpreters.py:560–597  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

558 self.assertEqual(out, 'it worked!')
559
560 def test_create_daemon_thread(self):
561 with self.subTest('isolated'):
562 expected = 'spam spam spam spam spam'
563 subinterp = _interpreters.create('isolated')
564 script, file = _captured_script(f"""
565 import threading
566 def f():
567 print('it worked!', end='')
568
569 try:
570 t = threading.Thread(target=f, daemon=True)
571 t.start()
572 t.join()
573 except RuntimeError:
574 print('{expected}', end='')
575 """)
576 with file:
577 _interpreters.run_string(subinterp, script)
578 out = file.read()
579
580 self.assertEqual(out, expected)
581
582 with self.subTest('not isolated'):
583 subinterp = _interpreters.create('legacy')
584 script, file = _captured_script("""
585 import threading
586 def f():
587 print('it worked!', end='')
588
589 t = threading.Thread(target=f, daemon=True)
590 t.start()
591 t.join()
592 """)
593 with file:
594 _interpreters.run_string(subinterp, script)
595 out = file.read()
596
597 self.assertEqual(out, 'it worked!')
598
599 def test_shareable_types(self):
600 interp = _interpreters.create()

Callers

nothing calls this directly

Calls 5

_captured_scriptFunction · 0.70
subTestMethod · 0.45
createMethod · 0.45
readMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected