forked from tscizzlebg/pywebview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.py
50 lines (36 loc) · 1.05 KB
/
event.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import multiprocessing
import threading
import logging
logger = logging.getLogger('pywebview')
class Event:
def __init__(self):
self._items = []
self._event = threading.Event()
def _initialize(self, is_multiprocessing):
if is_multiprocessing:
self._event = multiprocessing.Event()
def set(self, *args, **kwargs):
for func in self._items:
try:
func(*args, **kwargs)
except Exception as e:
logger.exception(e)
self._event.set()
def is_set(self):
return self._event.is_set()
def wait(self, timeout=0):
return self._event.wait(timeout)
def clear(self):
return self._event.clear()
def __add__(self, item):
self._items.append(item)
return self
def __sub__(self, item):
self._items.remove(item)
return self
def __iadd__(self, item):
self._items.append(item)
return self
def __isub__(self, item):
self._items.remove(item)
return self