forked from gpiozero/gpiozero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreads.py
39 lines (30 loc) · 855 Bytes
/
threads.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
from __future__ import (
unicode_literals,
print_function,
absolute_import,
division,
)
str = type('')
from threading import Thread, Event
_THREADS = set()
def _threads_shutdown():
while _THREADS:
for t in _THREADS.copy():
t.stop()
class GPIOThread(Thread):
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None):
if kwargs is None:
kwargs = {}
self.stopping = Event()
super(GPIOThread, self).__init__(group, target, name, args, kwargs)
self.daemon = True
def start(self):
self.stopping.clear()
_THREADS.add(self)
super(GPIOThread, self).start()
def stop(self):
self.stopping.set()
self.join()
def join(self):
super(GPIOThread, self).join()
_THREADS.discard(self)