summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2018-09-14 21:17:20 (GMT)
committerGitHub <noreply@github.com>2018-09-14 21:17:20 (GMT)
commit5903296045b586b9cd1fce0b1e02caf896028d1d (patch)
tree99e8900633096060e931980d52e063c044870d3c /Lib
parent3faaa8857a42a36383bb18425444e597fc876797 (diff)
downloadcpython-5903296045b586b9cd1fce0b1e02caf896028d1d.zip
cpython-5903296045b586b9cd1fce0b1e02caf896028d1d.tar.gz
cpython-5903296045b586b9cd1fce0b1e02caf896028d1d.tar.bz2
bpo-34651: Only allow the main interpreter to fork. (gh-9279)
When os.fork() is called (on platforms that support it) all threads but the current one are destroyed in the child process. Consequently we must ensure that all but the associated interpreter are likewise destroyed. The main interpreter is critical for runtime operation, so we must ensure that fork only happens in the main interpreter. https://bugs.python.org/issue34651
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test__xxsubinterpreters.py17
1 files changed, 3 insertions, 14 deletions
diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py
index ac76cc1..26032d6 100644
--- a/Lib/test/test__xxsubinterpreters.py
+++ b/Lib/test/test__xxsubinterpreters.py
@@ -824,23 +824,12 @@ class RunStringTests(TestBase):
expected = 'spam spam spam spam spam'
script = dedent(f"""
- # (inspired by Lib/test/test_fork.py)
import os
- pid = os.fork()
- if pid == 0: # child
+ try:
+ os.fork()
+ except RuntimeError:
with open('{file.name}', 'w') as out:
out.write('{expected}')
- # Kill the unittest runner in the child process.
- os._exit(1)
- else:
- SHORT_SLEEP = 0.1
- import time
- for _ in range(10):
- spid, status = os.waitpid(pid, os.WNOHANG)
- if spid == pid:
- break
- time.sleep(SHORT_SLEEP)
- assert(spid == pid)
""")
interpreters.run_string(self.id, script)