Repository navigation
Expand file tree
/
Copy pathparallel.py
More file actions
executable file
·60 lines (52 loc) · 1.54 KB
/
Copy pathparallel.py
File metadata and controls
executable file
·60 lines (52 loc) · 1.54 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
51
52
53
54
55
56
57
58
59
60
'''
This is an alpha implementation of a Wordpress plugin fingerprinting toolkit.
It uses makeshift binary search trees created by diffing SVN repository info
to determine not only if a plugin is installed
Copyright 2011, Ben Schmidt
Released under the GPL v3
'''
__author__ = "Ben Schmidt"
__copyright__ = "Copyright 2011, Ben Schmidt"
__credits__ = ["Ben Schmidt"]
__license__ = "GPL v3"
__version__ = "0.1"
__maintainer__ = "Ben Schmidt"
__email__ = "supernothing@spareclockcycles.org"
__status__ = "alpha"
import threading
class LockedIterator(object):
def __init__(self, it):
self.lock = threading.Lock()
self.it = it.__iter__()
def __iter__(self): return self
def next(self):
self.lock.acquire()
try:
return self.it.next()
finally:
self.lock.release()
class Parallel(threading.Thread):
'''
Crappy generic-ish thread for my common uses.
'''
def __init__(self,func,g,out,keywords):
self.g = g
self.func = func
self.out = out
self.kw = keywords
threading.Thread.__init__(self)
def run(self):
while 1:
try:
res = self.func(self.g.next(),self.kw)
if res != None:
self.out.append(res)
except StopIteration:
break
def get_threads(g,f,num,**keywords):
gen = LockedIterator(g)
threads,out = [],[]
for i in xrange(0,num):
threads.append(Parallel(f,g,out,keywords))
threads[-1].start()
return threads,out