-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy paththread_utils.py
More file actions
50 lines (37 loc) · 1.22 KB
/
thread_utils.py
File metadata and controls
50 lines (37 loc) · 1.22 KB
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
"""
PartsGenie (c) GeneGenie Bioinformatics 2025
@author: neilswainston
"""
# pylint: disable=too-few-public-methods
from threading import Thread
from partsgenie.utils import job_utils
class AbstractThread(job_utils.JobThread):
"""An AbstractThread base class."""
def __init__(self, query):
job_utils.JobThread.__init__(self)
self._query = query
self._results = []
def _fire_designs_event(self, status, iteration, message=''):
"""Fires an event."""
event = {
'update': {
'status': status,
'message': message,
'progress':
float(iteration) / len(self._query['designs']) * 100,
'iteration': iteration,
'max_iter': len(self._query['designs'])},
'query': self._query
}
if status == 'finished':
event['result'] = self._results
self._fire_event(event)
class ThreadPool(Thread):
"""Basic class to run job Threads sequentially."""
def __init__(self, threads):
self.__threads = threads
Thread.__init__(self)
def run(self):
for thread in self.__threads:
thread.start()
thread.join()