-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibThread.py
38 lines (29 loc) · 1.01 KB
/
libThread.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
#!/bin/env python
# -*- coding: utf-8 -*-
from threading import Thread, activeCount
from Queue import Queue
from time import sleep
class pool():
def __new__(self, number):
self.num_of_thread = 2
return self
def __init(self, number):
self.num_of_thread = number
def set_number(self, number):
self.num_of_thread = number
def map(self, target_func=False, args_tab=False, daemonize=False):
returns = []
queue = Queue()
for x in range(0, len(args_tab), self.num_of_thread):
for y in range(x,x+self.num_of_thread):
try:
new_thread = Thread(target = target_func, args=(queue, args_tab[y],))
new_thread.setDaemon(daemonize)
new_thread.start()
except IndexError:
break
while activeCount() > 1:
pass
for x in range(len(args_tab)):
returns.append(queue.get())
return returns