Exemple #1
0
def runBlock(instr, var, concurrent = True):
	from classes.proc import Proc
	for id in xrange(10):
		# init 10 processes
		proc = Proc(id, instr, var)
		proc.start()
		# .join() enforces current process to finish before iterating
		if(not(concurrent)):
			proc.join()
Exemple #2
0
def main():
	from lib.misc import runBlock, format
	import random, time

	# creates a block of 'sleep' Process() objects
	# the block of processes is also a Process() object
	sleepBlock = Proc('sleep', (('from lib.misc import runBlock\nrunBlock(%s, {})') % (format(sleep))))

	# note where the local variable dictionary goes in this invocation
	randBlock = Proc('random', (('from lib.misc import runBlock\nimport time, random\nrunBlock(%s, {\'rand\' : random.random()}), False') % (format(rand))))

	# the blocks here are run sequentially - though all processes within each block are concurrent
	print('running random sleep time block')
	sleepBlock.start()
	sleepBlock.join()

	print('running random init block')
	randBlock.start()
	randBlock.join()
Exemple #3
0
def main():
	from scripts.handler import handler

	# the queue is shared among all processes - Queue package handles synchronization
	queue = Queue()

	# handler logic to handle shared variables
	#	http://bit.ly/U1VNtT
	handler = Proc('handler', handler, {'queue' : queue, 'globals' : Manager().dict()})
	handler.daemon = True
	handler.start()

	proc1 = Proc('proc', instr1, {'queue' : queue})
	proc2 = Proc('proc', instr2, {'queue' : queue})

	proc1.start()
	proc1.join()
	proc2.start()
	proc2.join()

	# all processes have to finish before the final None queue input
	queue.put(None)
	handler.join()
Exemple #4
0
from multiprocessing import Process, Pipe, Manager, Queue
from classes.proc import Proc
from scripts.handler import handler
queue = Queue()
handler = Proc('handler', handler, {'queue' : queue, 'globals' : Manager().dict()})
handler.daemon = True
handler.start()
processes = Proc('processes', """procab = Proc('ab', \"\"\"
proc1 = Proc('ab_1', \\"\\"\\"SetReq('foo1', 'value1').send(self.var['queue'])

\\"\\"\\", {'queue' : self.var['queue']})
proc1.start()
proc1.join()
proc2 = Proc('ab_2', \\"\\"\\"SetReq('foo2', 'value2').send(self.var['queue'])
# note that foo1 is not initiated in this process
print(('value of foo1 is: %s') % (GetReq('foo1').recv(self.var['queue'])))
\\"\\"\\", {'queue' : self.var['queue']})
proc2.start()
proc2.join()
\"\"\", {'queue' : self.var['queue']})
procab.start()""", {'queue' : queue})
processes.start()
processes.join()
queue.put(None)
handler.join()