def main(): m = Manager() MAX_THREADS = 8 TIME_TO_CLIENTS = 0.5 pool = Pool(MAX_THREADS + 1) input_queue = m.JoinableQueue() output_queue = m.Queue() input_uqueue = m.Queue() com = [] for _ in range(MAX_THREADS): bqin = m.JoinableQueue() bqout = m.Queue() com.append((bqin, bqout)) threads = list(range(MAX_THREADS)) pool.apply_async(server_work, (input_queue, output_queue, input_uqueue, com, threads)) time.sleep(TIME_TO_CLIENTS) for j in range(MAX_THREADS): pool.apply_async( agent.run, (j, output_queue, input_queue, com[j][1], com[j][0], input_uqueue)) pool.close() pool.join()
def main(args): targets = readTargetsFromFile(args) httpAwareEntities = [] for target in targets: httpAwareEntities.append(HTTPAwareEntity(target)) print(str(len(httpAwareEntities)) + " IP adresses will be checked") print("Input file location : " + args.inputFileLocation[0]) print("Output file location : " + args.outputFileLocation[0]) with Pool(cpu_count() * 1) as pool: manager = Manager() workerQueue = manager.JoinableQueue() pool.apply_async(listener, (args.outputFileLocation[0], workerQueue)) #dosyaya aynı anda sadece 1 process yazması lazım, bu yüzden önce dosyaya yazacak processi açıp workerQueue'ya atıyorum try: #worker'lar çalışmaya başlıyor jobs = [] for httpAwareEntity in httpAwareEntities: job = pool.apply_async(worker, (workerQueue, httpAwareEntity)) jobs.append(job) # pool'daki workerlardan sonucları alıyorum for job in jobs: job.get() except Exception as e: print("EXCEPTION OCCURED! " + str(e)) #finally: #işimiz bitince workerQueue'ya kill komutu gönderiyorum workerQueue.put('kill') #workerQueue.join() pool.close() pool.join() print("Completed successfully")
def main(): m = Manager() MAX_THREADS = 4 pool = Pool(MAX_THREADS+1) input_queue = m.JoinableQueue() output_queue = m.Queue() input_uqueue = m.Queue() bqin = m.JoinableQueue() bqout = m.Queue() threads = list(range(MAX_THREADS)) pool.apply_async(server_work, (input_queue, output_queue, input_uqueue, bqin, bqout, threads)) for j in range(MAX_THREADS): pool.apply_async(agent.run, (j, output_queue, input_queue, bqout, bqin, input_uqueue)) pool.close() pool.join()
def main(): QUEUE_BUFFER_SIZE = 10 m = Manager() MAX_THREADS = 4 TIME_TO_CLIENTS = 0.5 pool = Pool(MAX_THREADS+1) input_uqueue = m.Queue(maxsize=QUEUE_BUFFER_SIZE) prediction_queue = [] for _ in range(MAX_THREADS): bqin = m.JoinableQueue(maxsize=QUEUE_BUFFER_SIZE) bqout = m.Queue(maxsize=QUEUE_BUFFER_SIZE) prediction_queue.append((bqin, bqout)) threads = list(range(MAX_THREADS)) pool.apply_async(server_work, (input_uqueue, prediction_queue, threads)) time.sleep(TIME_TO_CLIENTS) for j in range(MAX_THREADS): pool.apply_async(agent.run, (j, prediction_queue[j][1], prediction_queue[j][0], input_uqueue)) pool.close() pool.join()
def __init__(self, processes=1): self.pool = Pool(processes=processes) manager = Manager() self.que = manager.JoinableQueue() for _ in range(processes): self.pool.apply_async(process_worker, args=(self.que,))
if __name__ == '__main__': # Number of emails to send ... if args.jobs and args.workers: num_jobs = int(args.jobs) num_workers = int(args.workers) print("Sending %s emails" % (args.jobs)) start_time = time.time() m = Manager() # Establish communication queues tasks = m.JoinableQueue() results = m.Queue() # Start consumers num_consumers = multiprocessing.cpu_count() * num_workers # Enqueue jobs for i in range(num_jobs): tasks.put(Task(str(i) + "*****@*****.**")) # Add a poison pill for each consumer to close them while the for i in range(num_consumers): tasks.put(None) print("# Count of CPUs: %d" % multiprocessing.cpu_count()) print('Creating %d consumers' % num_consumers)
if infile is None: raise Exception('No input file provided.') outfile = args.output if outfile is None: raise Exception('No output file provided.') gtffile = args.gtf if gtffile is None: raise Exception('No gtf file provided.') isoformfile = args.isoform junctionfile = args.junction threads = int(args.threads) cells = args.cells contig = args.contig single_end = args.single_end m = Manager() q = m.JoinableQueue() p = Process(target=create_write_function(filename=outfile, bamfile=infile, version=__version__), args=(q, )) p.start() print('Stitching reads for {}'.format(infile)) start = time.time() construct_stitched_molecules(infile, outfile, gtffile, isoformfile, junctionfile, cells, contig, threads, single_end, q, __version__) q.put((None, None)) p.join() end = time.time()
results.append((integrated, refined)) if num_procs > 1: from multiprocessing import Manager, Process mgr = Manager() results = mgr.list() def worker(): for item in iter(q.get, None): do_work(item) q.task_done() q.task_done() q = mgr.JoinableQueue() procs = [] for i in range(num_procs): procs.append(Process(target=worker)) procs[-1].daemon = True procs[-1].start() for path in sys.argv[1:]: q.put(path) q.join() for p in procs: q.put(None) q.join()