I'm trying to use the multiprocessing library in python 2.7 and I found the behaviour of time.sleep() function a little bit disturbing. I need to control a timing critical hardware (on Raspberry PI) and my initial goal was to use a process dedicated to this using this library. But I found that putting the main process to sleep (time.sleep) also put the child process to sleep!?!? Is this the normal behaviour or I'm missing something? Here an exemple of code that reproduce my problem :
import time
from multiprocessing import Process, Queue
def child(q_display):
c = 9999999
while True:
data = q_display.get()
print data
print c
c = c - 1
if __name__ == '__main__':
q_display = Queue()
p = Process(target=child, args=(q_display,)).start()
data = 1
try:
while True:
q_display.put(data)
data = data + 1
print "MAIN ***********************************"
time.sleep(1)
except KeyboardInterrupt:
print "Keyboard CTRL-C !!!"
The output is this :
MAIN ***********************************
1
9999999
MAIN ***********************************
2
9999998
MAIN ***********************************
3
9999997
MAIN ***********************************
4
9999996
MAIN ***********************************
5
9999995
MAIN ***********************************
6
9999994
But this is what I expected:
MAIN ***********************************
1
9999999
9999998
9999997
9999996
9999995
9999994
9999993
9999992
MAIN ***********************************
2
9999991
9999990
9999989
9999988
9999987
9999986
9999985
9999984
... etc
What is I'm doing wrong?