Ugly, but it works. Synchronization is done via shared memory. And you need to pass stdin file descriptor to the child process and open it there.
import sys, select, os, datetime
from multiprocessing import Process, Value
from time import time
def func_control(fileno, switch):
sys.stdin = os.fdopen(fileno) #open stdin in this process
print "I'm doing stuff. Press Enter to stop me!"
some_str = raw_input("> ")
switch.value = 0
return
def func_1(i1, switch):
i1.value = 0
while switch.value != 0:
i1.value = i1.value+1
return 0
def func_2(i2, switch):
i2.value = 0
while switch.value != 0:
i2.value = i2.value+1
return 0
def start_fcontrol(start_time, fn, switch):
while time() < start_time.value: pass
func_control(fn, switch)
def start_f1(i1, start_time, switch):
while time() < start_time.value: pass
func_1(i1, switch)
def start_f2(i2, start_time, switch):
while time() < start_time.value: pass
func_2(i2, switch)
switch = Value('i', 1)
i1 = Value('i', 0)
i2 = Value('i', 0)
start_time = Value('d', time() + 1)
fn = sys.stdin.fileno() #get original file descriptor
procs = []
procs.append(Process(target=start_fcontrol, args=(start_time, fn, switch)))
procs.append(Process(target=start_f1, args=(i1, start_time, switch)))
procs.append(Process(target=start_f2, args=(i2, start_time, switch)))
map(lambda x: x.start(), procs)
map(lambda x: x.join(), procs)
print "i1 = ", i1.value
print "i2 = ", i2.value