Opened 9 years ago
Closed 9 years ago
#47 closed enhancement (fixed)
Enable "pause" and "resume" of thread
Reported by: | zhangjr | Owned by: | zhangjr |
---|---|---|---|
Priority: | major | Milestone: | pre-alpha |
Component: | model | Version: | 0.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Parent ID: | Parent Tickets: | ||
Estimated Number of Hours: | 0.0 | Add Hours to Ticket: | 0 |
Billable?: | yes | Total Hours: | 0 |
Description
class Me(threading.Thread):
def init(self):
threading.Thread.init(self)
self.paused = False
self.pause_cond = threading.Condition(threading.Lock())
def run(self):
while True:
with self.pause_cond:
while self.paused:
self.pause_cond.wait()
time.sleep(5)
def pause(self):
self.paused = True
self.pause_cond.acquire()
def resume(self):
self.paused = False
self.pause_cond.notify()
self.pause_cond.release()
Subtickets
Child Tickets
Change History (2)
comment:1 Changed 9 years ago by zhangjr
comment:2 Changed 9 years ago by zhangjr
- Resolution set to fixed
- Status changed from new to closed
Note: See
TracTickets for help on using
tickets.
self.can_run = threading.Event()
self.can_run.clear()
self.can_run.set()
swith self.can_run.isSet():
False: running
True: stop