Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Forking with python

  1. Feb 20, 2009 #1


    User Avatar
    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):
    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?
  2. jcsd
  3. Feb 26, 2009 #2
    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook