python-multiprocessing

how to add more items to a multiprocessing queue while script in motion

喜你入骨 提交于 2019-12-24 10:46:31
问题 I am trying to learn multiprocessing with queue. What I want to do is figure out when/how to "add more items to the queue" when the script is in motion. The below script is the baseline I am working from: import multiprocessing class MyFancyClass: def __init__(self, name): self.name = name def do_something(self): proc_name = multiprocessing.current_process().name print('Doing something fancy in {} for {}!'.format( proc_name, self.name)) def worker(q): obj = q.get() obj.do_something() if _

Can't put Future in Manager().Queue in Python

筅森魡賤 提交于 2019-12-24 09:28:26
问题 I have a bunch of client processes which make queries to a single worker process (which then processes them in batches) using a shared queue. However the clients need to know when the results are ready, so I tried putting a tuple with a concurrent.futures.Future along with the request in the queue, but Python throws a "cannot pickle" exception (this only happens with the future object). Is there a picklable version of Future that I can use for this purpose, or a better design altogether? 来源:

Python threading issue in OpenCV

我们两清 提交于 2019-12-24 08:07:05
问题 I was using threading module with OpenCV, I came accross a bizarre issue. When using thread I was unable to start the camera again to take video input. I would take one frame and then stop. While there was no problem like this when using multiprocessing module. I am unable to understand what causes this strange behaviour. This code summarizes the problem I have, The program will stuck when the thread is created second time. import cv2 import time import threading def open_cam(): count = 0 cam

How to unpack results from `Pool.map()`?

点点圈 提交于 2019-12-24 07:56:27
问题 I've got a function (preprocess_fit) that will first preprocess a data set (i.e. smoothing, baseline correction, and filters out bad data). The function then takes an initial guess for a parameter and then iterates through guesses to find the optimised fit and then returns const1, const2. The function also calculates a bunch of other parameters but they are not returned in this instance. I then need to loop this function over all files in a directory (~1000 files). I do this by using the

Python multiprocessing Pool API doesn't work efficiently when process count and worker count increased

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:16:14
问题 I'm trying to apply multiprocessing to parallelize my code. I have around 2000 works to get done. Since it is not practical to create 2000 simultaneous processes, I'm using python multiprocessing.pool API to get the work parallelized while managing the task queue. I tried creating 100 workers. But it took hours to finish which is not a big gain compared to sequential implementation. My laptop has 12 logical cores. Then I experimented incrementing both workers and works simultaneously .

How can I efficiently implement multithreading/multiprocessing in a Python web bot?

我只是一个虾纸丫 提交于 2019-12-24 04:32:19
问题 Let's say I have a web bot written in python that sends data via POST request to a web site. The data is pulled from a text file line by line and passed into an array. Currently, I'm testing each element in the array through a simple for-loop. How can I effectively implement multi-threading to iterate through the data quicker. Let's say the text file is fairly large. Would attaching a thread to each request be smart? What do you think the best approach to this would be? with open("c:\file.txt

Multiprocessing in Python: how to implement a loop over “apply_async” as “map_async” using a callback function

大城市里の小女人 提交于 2019-12-24 03:39:11
问题 I would like to integrate a system of differential equations for several parameter combinations using Python's multiprocessing module. So, the system should get integrated and the parameter combination should be stored as well as its index and the final value of one of the variables. While that works fine when I use apply_async - which is already faster than doing it in a simple for-loop - I fail to implement the same thing using map_async which seems to be faster than apply_async . The

Python's multiprocessing: speed up a for-loop for several sets of parameters, “apply” vs. “apply_async”

本小妞迷上赌 提交于 2019-12-24 03:30:00
问题 I would like to integrate a system of differential equations using a lot of different parameter combinations and store the variables’ final values that belong to a certain set of parameters. Therefore, I implemented a simple for-loop in which random initial conditions and parameter combinations are created, the system is integrated and the values of interest are stored in the respective arrays. Since I intend to do this for many parameter combinations for a rather complex system (here I only

Check for instance of Python multiprocessing.Connection?

自古美人都是妖i 提交于 2019-12-24 03:21:03
问题 Connection objects are created when opening a multiprocessing.Pipe . However, it's not clear how to check whether an object is an instance of a Connection . In Python3 (3.4, 3.3, !3.2), to detect an instance of Connection I can do: from multiprocessing.connection import Connection if isinstance(f, Connection): print("f is a Connection to a Pipe") from multiprocessing.dummy.connection import Connection also works on all Python3, but not Python2. However, this results in an ImportError using

How to pause processes in case they are consuming too much memory?

家住魔仙堡 提交于 2019-12-23 19:13:32
问题 Background: I process planetary imagery using a set of command-line utilities provided by the US Geologic Survey. Some of them are RAM hogs, to the extreme (10s of GB). USGS says it's just the way they run and don't have any plans to try to better manage the RAM. I built a Python wrapper to manipulate file lists to call the different steps to process the data in parts (such as all images taken in one color filter, and all taken in another, and all taken in another, etc.). Because things are