This is a simple code to test multiprocessing in python. f() prints a couple of integers every seconds and monitor() prints a warning if the ourput of f() crosses a threshold.
#!/usr/bin/python
from multiprocessing import Process
import time
def f():
global y
n = 20
for i in range (n):
y = i
print y
time.sleep(1)
def monitor():
n = 20
for i in range(20):
if y >= 10:
print 'y is greater than 10.'
time.sleep(1)
if __name__ == '__main__':
p1 = Process(target = f, args = ())
p2 = Process(target = monitor, args = ())
p1.start()
p2.start()
p1.join()
p2.join()
The problem is that nothing happens when I execute this code. I don't even get an error. How can I fix this? The same process works perfectly if I use threading instead of multiprocessing, but I'd like to be able to do the same stuff with multiprocessing too.
python v 2.7.6
OS: windows 7