queue

Overriding multiprocessing.queues.Queue put method

Overriding multiprocessing.queues.Queue put method Question: I want to implement a multiprocessing.Queue that does not add an element that already exists. Using Python STL Queue I had no problem, following this response. For multiprocessing I had some issues that I solved thanks to this For that I do the following: from multiprocessing.queues import Queue from multiprocessing …

Total answers: 2

How to make a Python threaded program (with Locks) to run on multi-process?

How to make a Python threaded program (with Locks) to run on multi-process? Question: I have a multi-threaded program, and I want to let the user choose how to run them, either in serial, multi threads or multi cores, at least at the top level. A runnable demo is shown below illustrating my program’s logic. …

Total answers: 3

Knowing when you've read everything off a multiprocessing Queue

Knowing when you've read everything off a multiprocessing Queue Question: I have some code that farms out work to tasks. The tasks put their results on a queue, and the main thread reads these results from the queue and deals with them. from multiprocessing import Process, Queue, Pool, Manager import uuid def handle_task(arg, queue, end_marker): …

Total answers: 1

How is the multiprocessing.Queue instance serialized when passed as an argument to a multiprocessing.Process?

How is the multiprocessing.Queue instance serialized when passed as an argument to a multiprocessing.Process? Question: A related question came up at Why I can’t use multiprocessing.Queue with ProcessPoolExecutor?. I provided a partial answer along with a workaround but admitted that the question raises another question, namely why a multiprocessing.Queue instance can be passed as the …

Total answers: 2

Queries with python logging in Multiprocessing and QueueHandler

Queries with python logging in Multiprocessing and QueueHandler Question: Background I am trying to learn more about multiprocessing in Python. One requirement for my application is sending logs from all processes to a single file. I was going through this tutorial and the Logging cookbook example. The code consists of a main process that launches …

Total answers: 1

Why I can't use multiprocessing.Queue with ProcessPoolExecutor?

Why I can't use multiprocessing.Queue with ProcessPoolExecutor? Question: When I run the below code: from concurrent.futures import ProcessPoolExecutor, as_completed from multiprocessing import Queue q = Queue() def my_task(x, queue): queue.put("Task Complete") return x with ProcessPoolExecutor() as executor: tasks = [executor.submit(my_task, i, q) for i in range(10)] for task in as_completed(tasks): print(task.result()) I get this error: …

Total answers: 1

How to create a queue of dictionaries per customer?

How to create a queue of dictionaries per customer? Question: I am a beginner at python. We have an assignment that is requiring us to create a queue of dictionaries. I am unsure how to do this inside of a list. Here is my code (btw this is play code, not used functionally) My main …

Total answers: 1

Is it possible for multiple python files to use one queue?

Is it possible for multiple python files to use one queue? Question: one script(datamanger.py) from multiprocessing import Manager q = Manager().Queue() The other two scripts are like this from datamanager import q import time while True: time.sleep(1) q.put(1) from datamanager import q while True: if not q.empty(): data = q.get() print(data) Is it possible to …

Total answers: 2

How to get `multiprocessing.queues.Queue.qsize()` on macOS?

How to get `multiprocessing.queues.Queue.qsize()` on macOS? Question: This is an old issue which suggested workaround does not work. Below is a complete example showing how the suggested approach fails. Uncomment L31 for error. import multiprocessing import os import time from multiprocessing import get_context from multiprocessing.queues import Queue class SharedCounter(object): def __init__(self, n=0): self.count = multiprocessing.Value(‘i’, …

Total answers: 1

Using list of queues in a list

Using list of queues in a list Question: num_of_stacks = int((len(config[0]) + 1)/4) stacks = [Queue() for i in range(num_of_stacks)] # stacks = list(map(Queue, range(num_of_stacks))) print(stacks) for line in config[len(config)-2::-1]: print(stacks) for i in range(0, len(line), 4): print(int(i/4), line[i+1: i+2]) if line[i+1: i+2] != ‘ ‘: print(stacks[int(i/4)]) stacks[int(i/4)].put(line[i+1: i+2]) print(line) I am writing a program …

Total answers: 1