A pausable thread that simply runs a loop
| 70 | |
| 71 | |
| 72 | class LoopThread(StoppableThread): |
| 73 | """ A pausable thread that simply runs a loop""" |
| 74 | |
| 75 | def __init__(self, func, pausable=True): |
| 76 | """ |
| 77 | Args: |
| 78 | func: the function to run |
| 79 | """ |
| 80 | super(LoopThread, self).__init__() |
| 81 | self._func = func |
| 82 | self._pausable = pausable |
| 83 | if pausable: |
| 84 | self._lock = threading.Lock() |
| 85 | self.daemon = True |
| 86 | |
| 87 | def run(self): |
| 88 | while not self.stopped(): |
| 89 | if self._pausable: |
| 90 | self._lock.acquire() |
| 91 | self._lock.release() |
| 92 | self._func() |
| 93 | |
| 94 | def pause(self): |
| 95 | """ Pause the loop """ |
| 96 | assert self._pausable |
| 97 | self._lock.acquire() |
| 98 | |
| 99 | def resume(self): |
| 100 | """ Resume the loop """ |
| 101 | assert self._pausable |
| 102 | self._lock.release() |
| 103 | |
| 104 | |
| 105 | class ShareSessionThread(threading.Thread): |
no outgoing calls
no test coverage detected
searching dependent graphs…