Forking with python

  • Thread starter daniel_i_l
  • Start date


Gold Member
For some reasons, if I fork a proccess (or start a thread) in python and let the original program wait for user input, the the forked proccess doesn't print anything to the screen untill the newline character is printed. For example (i used '----' instead of indent):
ret = os.fork()
if ret == 0:
----print 'test',
----data = raw_input('input: ')
doesn't print any thing to the screen. But if the 3rd line is instead
print 'test' (without comma)
then it does.
Why is this?
I'm no expert in this, but this reminds me of mutex situation.

Often in programs, different threads or processes use the same memory, so in order to avoid corruption, when a piece of code accesses this memory, it locks it to other code until its done.

This sounds exactly to be the case with your console you are running your code on. Threads and processes need to wait their turn, but I could be wrong, but to me this most likely seems to be the case.

Want to reply to this thread?

"Forking with python" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving

Top Threads