MCPcopy Create free account
hub / github.com/FreeformRobotics/OTS / FutureResult

Class FutureResult

lib/nn/modules/comm.py:18–39  ·  view source on GitHub ↗

A thread-safe future implementation. Used only as one-to-one pipe.

Source from the content-addressed store, hash-verified

16
17
18class FutureResult(object):
19 """A thread-safe future implementation. Used only as one-to-one pipe."""
20
21 def __init__(self):
22 self._result = None
23 self._lock = threading.Lock()
24 self._cond = threading.Condition(self._lock)
25
26 def put(self, result):
27 with self._lock:
28 assert self._result is None, 'Previous result has\'t been fetched.'
29 self._result = result
30 self._cond.notify()
31
32 def get(self):
33 with self._lock:
34 if self._result is None:
35 self._cond.wait()
36
37 res = self._result
38 self._result = None
39 return res
40
41
42_MasterRegistry = collections.namedtuple('MasterRegistry', ['result'])

Callers 1

register_slaveMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected