MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / LoopThread

Class LoopThread

tensorpack/utils/concurrency.py:72–102  ·  view source on GitHub ↗

A pausable thread that simply runs a loop

Source from the content-addressed store, hash-verified

70
71
72class 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
105class ShareSessionThread(threading.Thread):

Callers 2

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…