multiprocessing

Python 3.5 multiprocessing pool and queue don't work

女生的网名这么多〃 提交于 2020-03-20 06:06:49
问题 I encounter a multiprocessing problem. The code is included below. The code can execute as expected, but when uncommenting self.queue = multiprocessing.Queue() , this program will exit immediately and it seems that the subprocess can't be started successfully. I don't know what happened. Could someone help me out? Many Thanks! import multiprocessing import time class Test: def __init__(self): self.pool = multiprocessing.Pool(1) #self.queue = multiprocessing.Queue() def subprocess(self): for i

Python multiprocessing Pool map and imap

狂风中的少年 提交于 2020-03-17 12:22:08
问题 I have a multiprocessing script with pool.map that works. The problem is that not all processes take as long to finish, so some processes fall asleep because they wait until all processes are finished (same problem as in this question). Some files are finished in less than a second, others take minutes (or hours). If I understand the manual (and this post) correctly, pool.imap is not waiting for all the processes to finish, if one is done, it is providing a new file to process. When I try

Is multithreading in python a myth?

我们两清 提交于 2020-03-17 08:43:26
问题 To the best of my knowledge, multiple threads can be spawned within the system concurrently but 2 different threads can not access or modify the same resource at the same time. I have even tried many things like creating many threads and putting them in a queue etc. But always I used to hear people say multithreading is not available in Python and that instead you can use multiprocessing to take advantage of multicore CPUs. I this true? Are Python threads only green threads, not real

Chrome crashes after several hours while multiprocessing using Selenium through Python

邮差的信 提交于 2020-03-16 07:36:42
问题 This is the error traceback after several hours of scraping: The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed. This is my setup of selenium python: #scrape.py from selenium.common.exceptions import * from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.chrome.options

Python multi-processing

假如想象 提交于 2020-03-15 04:54:59
问题 I have a large list containing binary encoded strings that I used to process in a single function before, like so: """ just included this to demonstrate the 'data' structure """ data=np.zeros(250,dtype='float32, (250000,2)float32') def func numpy_array(data, peaks): rt_counter=0 for x in peaks: if rt_counter %(len(peaks)/20) == 0: update_progress() peak_counter=0 data_buff=base64.b64decode(x) buff_size=len(data_buff)/4 unpack_format=">%dL" % buff_size index=0 for y in struct.unpack(unpack

Python multi-processing

狂风中的少年 提交于 2020-03-15 04:54:40
问题 I have a large list containing binary encoded strings that I used to process in a single function before, like so: """ just included this to demonstrate the 'data' structure """ data=np.zeros(250,dtype='float32, (250000,2)float32') def func numpy_array(data, peaks): rt_counter=0 for x in peaks: if rt_counter %(len(peaks)/20) == 0: update_progress() peak_counter=0 data_buff=base64.b64decode(x) buff_size=len(data_buff)/4 unpack_format=">%dL" % buff_size index=0 for y in struct.unpack(unpack

Poor scaling of multiprocessing Pool.map() on a list of large objects: How to achieve better parallel scaling in python?

别等时光非礼了梦想. 提交于 2020-03-13 06:29:12
问题 Let us define : from multiprocessing import Pool import numpy as np def func(x): for i in range(1000): i**2 return 1 Notice that func() does something and it always returns a small number 1 . Then, I compare an 8-core parallel Pool.map() v/s a serial, python built in, map() n=10**3 a=np.random.random(n).tolist() with Pool(8) as p: %timeit -r1 -n2 p.map(func,a) %timeit -r1 -n2 list(map(func,a)) This gives : 38.4 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 2 loops each) 200 ms ± 0 ns per

Python - multiprocessing while writing to a single result file

随声附和 提交于 2020-03-05 12:53:33
问题 I am really new to the multiprocessing package and I am failing to get the task done. I have lots of calculations to do on a list of objects. The results I need to write down are saved in those objects, too. The results should be written in a single file as soon as the process finished the calculations (the way I got it at least working, waits until all calculations are done). import multiprocessing import time import csv class simpl(): def __init__(self, name, val): self.name = name self.val

Multiprocessing so slow

丶灬走出姿态 提交于 2020-03-05 09:12:11
问题 I have a function that does the following : Take a file as input and does basic cleaning. Extract the required items from the file and then write them in a pandas dataframe. The dataframe is finally converted into csv and written into a folder. This is the sample code: def extract_function(filename): with open(filename,'r') as f: input_data=f.readlines() try: // some basic searching pattern matching extracting // dataframe creation with 10 columns and then extracted values are filled in empty

Multiprocessing so slow

笑着哭i 提交于 2020-03-05 09:11:53
问题 I have a function that does the following : Take a file as input and does basic cleaning. Extract the required items from the file and then write them in a pandas dataframe. The dataframe is finally converted into csv and written into a folder. This is the sample code: def extract_function(filename): with open(filename,'r') as f: input_data=f.readlines() try: // some basic searching pattern matching extracting // dataframe creation with 10 columns and then extracted values are filled in empty