A tool to enforce non-reentrancy. Mostly used on DataFlow whose :meth:`get_data` is stateful, so that multiple instances of the iterator cannot co-exist.
| 22 | |
| 23 | |
| 24 | class DataFlowReentrantGuard(object): |
| 25 | """ |
| 26 | A tool to enforce non-reentrancy. |
| 27 | Mostly used on DataFlow whose :meth:`get_data` is stateful, |
| 28 | so that multiple instances of the iterator cannot co-exist. |
| 29 | """ |
| 30 | def __init__(self): |
| 31 | self._lock = threading.Lock() |
| 32 | |
| 33 | def __enter__(self): |
| 34 | self._succ = self._lock.acquire(False) |
| 35 | if not self._succ: |
| 36 | raise threading.ThreadError("This DataFlow is not reentrant!") |
| 37 | |
| 38 | def __exit__(self, exc_type, exc_val, exc_tb): |
| 39 | self._lock.release() |
| 40 | return False |
| 41 | |
| 42 | |
| 43 | class DataFlowMeta(ABCMeta): |
no outgoing calls
no test coverage detected