I have two threads, and, I want one thread to run for 10 seconds, and then have this thread stop, whilst another thread executes and then the first thread starts up again; this process is repeated. So e.g.
from threading import Thread import sys import time class Worker(Thread): Listened = False; def __init__(self): while 1: if(self.Listened == False): time.sleep(0) else: time.sleep(20) for x in range(0, 10): print "I'm working" self.Listened = True class Processor(Thread): Listened = False; def __init__(self): # this is where I'm confused!! Worker().start() Processer().start()
(P.S. I have indented correctly, however, posting seems to have messed it up a bit)
Basically, what I want is:
The worker thread works for 10 seconds (or so) and then stops, the "processor" starts up and, once the processor has processed the data from the last run of the "Worker" thread, it then re-starts the "worker" thread up. I don't specifically have to re-start the "worker" thread from that current position, it can start from the beginning.
Does anyone have any ideas?
Edited 3 Years Ago by phorce