| 333 | # |
| 334 | |
| 335 | class Event(object): |
| 336 | |
| 337 | def __init__(self, *, ctx): |
| 338 | self._cond = ctx.Condition(ctx.Lock()) |
| 339 | self._flag = ctx.Semaphore(0) |
| 340 | |
| 341 | def is_set(self): |
| 342 | with self._cond: |
| 343 | if self._flag.acquire(False): |
| 344 | self._flag.release() |
| 345 | return True |
| 346 | return False |
| 347 | |
| 348 | def set(self): |
| 349 | with self._cond: |
| 350 | self._flag.acquire(False) |
| 351 | self._flag.release() |
| 352 | self._cond.notify_all() |
| 353 | |
| 354 | def clear(self): |
| 355 | with self._cond: |
| 356 | self._flag.acquire(False) |
| 357 | |
| 358 | def wait(self, timeout=None): |
| 359 | with self._cond: |
| 360 | if self._flag.acquire(False): |
| 361 | self._flag.release() |
| 362 | else: |
| 363 | self._cond.wait(timeout) |
| 364 | |
| 365 | if self._flag.acquire(False): |
| 366 | self._flag.release() |
| 367 | return True |
| 368 | return False |
| 369 | |
| 370 | def __repr__(self): |
| 371 | set_status = 'set' if self.is_set() else 'unset' |
| 372 | return f"<{type(self).__qualname__} at {id(self):#x} {set_status}>" |
| 373 | # |
| 374 | # Barrier |
| 375 | # |
no outgoing calls
no test coverage detected
searching dependent graphs…