I am attempting to run a program I have written for 1 second. If 1 second goes by then I want to switch to a new process and STOP the other one immediately. The following is my attempt
p_create_time=time.time()
p = multiprocessing.Process(target=queen4(number, numberblocked))
p.start()
p.join()
i=0
while i==0:
if abs(time.time() - p_create_time) >= TIMEOUT:
p.terminate()
print "Stoped queens4.lp starting queens11.lp"
i=1
continue
if not p.is_alive():
i=2
print str(i)
t=abs(time.time()-p_create_time)
if i==1:
d = multiprocessing.Process(target=queen11(number, numberblocked,t))
d.start()
Instead of doing what I want if this goes over TIMEOUT then this script finishes p
then runs d
but if it does not timeout then it works correctly. So my two questions are why is this not working (I am new to python) and ideas on how to fix it.
Thanks