Description
Bug report
Bug description:
Actual behavior
Having a Thread running which is waiting for a user cli input lets a newely started multiprocessing Process hang until the user provides the cli input for the Thread once.
The target method of the Process will not get called until the input is provided.
After the user has provided the input for the thread, the target of the Process beginns executing.
Regardless if the Thread is now waiting for further user input, the target of the Process continues running.
Expected behavior
I would expect the target of the Process to begin executing directly when start
gets called, regardless of any Thread waiting for user input.
Minimal example
from threading import Thread
from multiprocessing import Process
import time
def thread_worker():
while True:
input()
print(f"Thread: {time.time_ns()}")
time.sleep(1)
def process_worker():
while True:
print(f"Process: {time.time_ns()}")
time.sleep(1)
def main():
t = Thread(target=thread_worker)
t.start()
p = Process(target=process_worker)
p.start()
while True:
print(f"Parent: {time.time_ns()}")
time.sleep(1)
if __name__ == '__main__':
main()
Parent: 1744127459390331500
Parent: 1744127460391104200
Parent: 1744127461391702600
Parent: 1744127462391891200
Parent: 1744127463391976800
<-- User pressed <Enter> here
Thread: 1744127463907895600
Process: 1744127464027620700
Parent: 1744127464392826400
Process: 1744127465027796400
Parent: 1744127465393627600
Process: 1744127466028309500
Parent: 1744127466394346500
Process: 1744127467028522100
Parent: 1744127467395162900
<-- User pressed <Enter> here
Thread: 1744127468003765700
Process: 1744127468029055500
Parent: 1744127468395581600
Process: 1744127469029577600
Parent: 1744127469395885500
Process: 1744127470030224200
Parent: 1744127470396392600
Process: 1744127471030760100
Parent: 1744127471396828100
I find it unexpected that before the first <-- User pressed <Enter> here
there is no output of the Process.
CPython versions tested on:
3.12
Operating systems tested on:
Windows