mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Issue #15646: Prevent equivalent of a fork bomb when using multiprocessing
on Windows without the "if __name__ == '__main__'" idiom.
This commit is contained in:
parent
fe9efc5732
commit
faee75c33a
4 changed files with 43 additions and 2 deletions
16
Lib/test/mp_fork_bomb.py
Normal file
16
Lib/test/mp_fork_bomb.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import multiprocessing
|
||||
|
||||
def foo(conn):
|
||||
conn.send("123")
|
||||
|
||||
# Because "if __name__ == '__main__'" is missing this will not work
|
||||
# correctly on Windows. However, we should get a RuntimeError rather
|
||||
# than the Windows equivalent of a fork bomb.
|
||||
|
||||
r, w = multiprocessing.Pipe(False)
|
||||
p = multiprocessing.Process(target=foo, args=(w,))
|
||||
p.start()
|
||||
w.close()
|
||||
print(r.recv())
|
||||
r.close()
|
||||
p.join()
|
Loading…
Add table
Add a link
Reference in a new issue