-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread.py
More file actions
34 lines (25 loc) · 808 Bytes
/
thread.py
File metadata and controls
34 lines (25 loc) · 808 Bytes
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
#!/usr/bin/env python3
import threading
class threadWorker(object):
def __init__(self, worker, daemon):
self._worker = worker
self._threadWork = threading.Thread(target=self._worker)
self._daemon = daemon
def get_daemon(self):
return self._daemon
def set_daemon(self, value):
self._daemon = value
def start(self):
self._threadWork.daemon = self._daemon
self._threadWork.start()
def stop(self):
self._threadWork.join()
class threadHandler:
def __init__(self, workers = []):
self._workers = workers
def start(self):
for worker in self._workers:
worker.start()
def stop(self):
for worker in self._workers:
worker.stop()