-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskThreaderModule.py
More file actions
30 lines (26 loc) · 808 Bytes
/
Copy pathTaskThreaderModule.py
File metadata and controls
30 lines (26 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
from threading import *
import os
import time
import linecache
# The 'data' argument needs to be a list with functions.
def runTasks(data):
if type(data) is list and len(data) > 0:
loop(data)
return True
else:
return False
# Loops through data list, runs functions, then starts "finished()" when complete.
def loop(data):
try:
r = range(0, len(data))
for x in r:
# Initializes processes.
locals()['TaskThreaderModuleloop%s' % x] = Thread(target=data[x])
for x in r:
# Starts processes.
locals()['TaskThreaderModuleloop%s' % x].start()
# Waits for functions to complete.
for x in r:
locals()['TaskThreaderModuleloop%s' % x].join()
except:
PrintException()