def main(workers=10): """ Executes main function of mini-framework's Control thread. :param workers: Integer detailing number of worker FIFO threads to employ """ start_logging() log_info("New multiprocessing session with {} workers".format(workers)) # Input JoinableQueue and Output Queue inq = JoinableQueue(maxsize=int(workers * 1.5)) outq = Queue(maxsize=int(workers * 1.5)) ot = OutThread(workers, outq) ot.start() for _ in range(workers): w = WorkerThread(inq, outq) w.start() # Create a sequence of a 1000 random alphabetic characters random_chars = (ascii_letters[randint(0, 51)] for _ in range(1000)) # Keep input queue loaded for as long as possible # Feed the process pool with work units for work in enumerate(random_chars): inq.put(work) # Fill the input queue with Nones to shut the worker threads down # which terminates the process pool for _ in range(workers): inq.put(None) inq.join() print("Control process terminating")
def main(workers=10): """ Executes main function of mini-framework's Control thread. :param workers: Integer detailing number of worker FIFO threads to employ """ start_logging() log_info("New multiprocessing session with {} workers".format(workers)) # Input JoinableQueue and Output Queue inq = JoinableQueue(maxsize=int(workers*1.5)) outq = Queue(maxsize=int(workers*1.5)) ot = OutThread(workers, outq) ot.start() for _ in range(workers): w = WorkerThread(inq, outq) w.start() # Create a sequence of a 1000 random alphabetic characters random_chars = (ascii_letters[randint(0, 51)] for _ in range(1000)) # Keep input queue loaded for as long as possible # Feed the process pool with work units for work in enumerate(random_chars): inq.put(work) # Fill the input queue with Nones to shut the worker threads down # which terminates the process pool for _ in range(workers): inq.put(None) inq.join() print("Control process terminating")
def main(workers=WORKERS): """ Executes main function of mini-framework's Control thread. :param workers: Integer detailing number of worker FIFO threads to employ """ log_info("New mini-framework session with {} workers".format(workers)) inq = Queue(maxsize=int(workers * 1.5)) outq = Queue(maxsize=int(workers * 1.5)) ot = OutThread(workers, outq) ot.start() for _ in range(workers): w = WorkerThread(inq, outq) w.start() # Create a sequence of a 1000 random alphabetic characters random_chars = (ascii_letters[randint(0, 51)] for _ in range(1000)) # Keep input queue loaded for as long as possible for work in enumerate(random_chars): inq.put(work) # Fill the input queue with Nones to shut the worker threads down for _ in range(workers): inq.put(None) inq.join() print("Control thread terminating") log_info("Mini-framework finished. Len: {} chars".format(len(ot.output)))
def run(): WORKERS = 10 inq = Queue(maxsize=int(WORKERS * 1.5)) outq = Queue(maxsize=int(WORKERS * 1.5)) ot = OutThread(WORKERS, outq) ot.start() for i in range(WORKERS): w = WorkerThread(inq, outq) w.start() instring = randomstring() for work in enumerate(instring): inq.put(work) for i in range(WORKERS): inq.put(None) inq.join() print("Control thread terminating")
def control(): WORKERS = 10 inq = Queue(maxsize=int(WORKERS*1.5)) outq = Queue(maxsize=int(WORKERS*1.5)) ot = OutThread(WORKERS, outq) ot.start() for i in range(WORKERS): w = WorkerThread(inq, outq) w.start() instring = [chr(randint(97, 122)) for _ in range(1000)] for work in enumerate(instring): inq.put(work) for i in range(WORKERS): inq.put(None) inq.join() print("Control thread terminating")
def process(n): WORKERS = 10 inq = JoinableQueue(maxsize = int(WORKERS * 1.5)) outq = Queue(maxsize = int(WORKERS * 1.5)) ot = OutThread(WORKERS, outq, sorting = True) ot.start() for i in range(WORKERS): w = WorkerThread(inq, outq) w.start() instring = "".join(random.choice(string.ascii_letters) for i in range(n)) for work in enumerate(instring): inq.put(work) for i in range(WORKERS): inq.put(None) inq.join() print("Control process terminating.")
def run(): WORKERS = 10 inq = Queue(maxsize=int(WORKERS*1.5)) outq = Queue(maxsize=int(WORKERS*1.5)) ot = OutThread(WORKERS, outq) ot.start() for i in range(WORKERS): w = WorkerThread(inq, outq) w.start() # generate a random string of alphabetic characters of length one thousand instring = (''.join(random.choice(string.ascii_letters) for i in range(1000))) for work in enumerate(instring): inq.put(work) for i in range(WORKERS): inq.put(None) inq.join() print("Control thread terminating")
def run(): WORKERS = 10 inq = Queue(maxsize=int(WORKERS * 1.5)) outq = Queue(maxsize=int(WORKERS * 1.5)) ot = OutThread(WORKERS, outq) ot.start() for i in range(WORKERS): w = WorkerThread(inq, outq) w.start() # generate a random string of alphabetic characters of length one thousand instring = (''.join( random.choice(string.ascii_letters) for i in range(1000))) for work in enumerate(instring): inq.put(work) for i in range(WORKERS): inq.put(None) inq.join() print("Control thread terminating")
def randstr(length=1000): result = [] for i in range(length): result.append(ascii_letters[randrange(len(ascii_letters))]) return "".join(result) if __name__ == "__main__": WORKERS = 10 inq = JoinableQueue(maxsize=int(WORKERS * 1.5)) outq = Queue(maxsize=int(WORKERS * 1.5)) ot = OutThread(WORKERS, outq) ot.start() for i in range(WORKERS): w = WorkerThread(inq, outq) w.start() instring = randstr() # put work on the queue for work in enumerate(instring): inq.put(work) # terminate the process pool for i in range(WORKERS): inq.put(None) inq.join() print("Control process terminating")
""" control.py: Creates queues, starts output and worker processes, and pushes inputs into the input queue. """ from multiprocessing import Queue, JoinableQueue from output import OutThread from worker import WorkerProcess from alphaGenerator import alphaGen if __name__ == '__main__': WORKERS = 10 inq = JoinableQueue(maxsize=int(WORKERS * 1.5)) outq = Queue(maxsize=int(WORKERS * 1.5)) ot = OutThread(WORKERS, outq, sorting=True) ot.start() for i in range(WORKERS): w = WorkerProcess(inq, outq) w.start() # instring = input("Words of wisdom: ") instring = alphaGen(100) # feed the process pool with work units for work in enumerate(instring): inq.put(work) # terminate the process pool for i in range(WORKERS): inq.put(None) inq.join() print("Control process terminating")
""" control.py: Creates queues, starts output and worker threads, and pushes inputs into the input queue. """ from multiprocessing import Queue, JoinableQueue from output import OutThread from worker import WorkerThread from random import choice from string import ascii_letters if __name__ == '__main__': WORKERS = 10 inq = JoinableQueue(maxsize=int(WORKERS * 1.5)) outq = Queue(maxsize=int(WORKERS * 1.5)) ot = OutThread(WORKERS, outq) ot.start() for i in range(WORKERS): w = WorkerThread(inq, outq) w.start() instring = '' for i in range(1000): instring += choice(ascii_letters) for work in enumerate(instring): inq.put(work) for i in range(WORKERS): inq.put(None) inq.join() print("Control thread terminating")
start output process start worker processes pushes inputs into the input queue using the output of a generator """ from multiprocessing import Queue, JoinableQueue from output import OutThread from worker import WorkerProcess from alphaGenerator import alphaGen if __name__ == '__main__': WORKERS = 2 inq = JoinableQueue(maxsize=int(WORKERS * 1.5)) outq = Queue(maxsize=int(WORKERS * 1.5)) ot = OutThread(WORKERS, outq, sorting=False) ot.start() for i in range(WORKERS): w = WorkerProcess(inq, outq) w.start() instring = alphaGen(10) # feed the process pool with work units for work in enumerate(instring): inq.put(work) # terminate the process pool for i in range(WORKERS): inq.put(None) inq.join() print("input is ", instring)