Skip to content

Commit 94b6d09

Browse files
committed
Add some comments.
1 parent 4012aa6 commit 94b6d09

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Lib/test/test_interpreters/test_lifecycle.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,20 @@ def test_interrupt_thread_with_interpreter(self):
195195
with subprocess.Popen([
196196
sys.executable, "-c",
197197
"import threading, _interpreters\n"
198-
"def run_interp(): _interpreters.run_string(_interpreters.create(), 'import time; print(1, flush=True); time.sleep(5)')\n"
198+
"def run_interp(): _interpreters.run_string(_interpreters.create(),"
199+
"'import time; print(1, flush=True); time.sleep(5)')\n"
199200
"threading.Thread(target=run_interp).start()"
200201
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as proc:
201202
with proc.stdout:
203+
# Make sure that the thread has actually started
202204
self.assertEqual(proc.stdout.read(1), "1")
203205

206+
# Send a KeyboardInterrupt to the process
204207
proc.send_signal(signal.SIGINT)
205208
with proc.stderr:
206209
self.assertIn("KeyboardInterrupt", proc.stderr.read())
207210
proc.wait()
211+
# Make sure it didn't segfault
208212
self.assertEqual(proc.returncode, 0)
209213

210214
if __name__ == '__main__':

Python/pystate.c

+3
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,9 @@ PyThreadState_Swap(PyThreadState *newts)
24142414
PyThreadState *
24152415
_PyThreadState_SwapAttached(PyThreadState *tstate)
24162416
{
2417+
// Evil thread state magic: we manually
2418+
// mark it as unbound so we can re-attach it
2419+
// to current thread.
24172420
tstate->_status.bound_gilstate = 0;
24182421
tstate->_status.holds_gil = 0;
24192422
tstate->_status.active = 0;

0 commit comments

Comments
 (0)