Skip to content

Commit c2fc3f7

Browse files
author
Matt George
committed
first stab, really just a backup
1 parent 001f614 commit c2fc3f7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pyres/horde.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
try:
2+
import multiprocessing
3+
except:
4+
import sys
5+
sys.exit("multiprocessing was not available")
6+
import os, datetime, time, signal, sys
7+
from pyres import ResQ
8+
9+
from pyres.exceptions import NoQueueError
10+
from pyres.worker import Worker
11+
class Minion(multiprocessing.Process):
12+
def __init__(self, conn, queue):
13+
self.conn = conn
14+
self.q = queue
15+
super(Minion,self).__init__(name='Minion')
16+
17+
def run(self):
18+
while True:
19+
job = self.q.get()
20+
print 'pid: %s is running %s ' % (self.pid,job)
21+
22+
class Khan(object):
23+
_workers = {}
24+
def __init__(self, pool_size=5):
25+
self.pool_size = pool_size
26+
def run():
27+
q = multiprocessing.Queue()
28+
for i in range(pool_size):
29+
parent_conn, child_conn = multiprocessing.Pipe()
30+
m = Minion(child_conn, q)
31+
print m.pid
32+
m.start()
33+
print m.pid
34+
self._workers[m.pid] = parent_conn
35+
36+
37+
if __name__ == "__main__":
38+
k = Khan()
39+
k.run()

0 commit comments

Comments
 (0)