concurrent.futures

recursion max error when when using futures.ProcessPoolExecutor but not futures.ThreadPoolExecutor with PRAW wrapper

微笑、不失礼 提交于 2019-12-22 09:17:14
问题 I am using this code to scrape an API: submissions = get_submissions(1) with futures.ProcessPoolExecutor(max_workers=4) as executor: #or using this: with futures.ThreadPoolExecutor(max_workers=4) as executor: for s in executor.map(map_func, submissions): collection_front.update({"time_recorded":time_recorded}, {'$push':{"thread_list":s}}, upsert=True) It works great/fast with threads but when I try to use processes I get a full queue and this error: File "/usr/local/lib/python3.4/dist

Function that multiprocesses another function

江枫思渺然 提交于 2019-12-22 08:40:42
问题 I'm performing analyses of time-series of simulations. Basically, it's doing the same tasks for every time steps. As there is a very high number of time steps, and as the analyze of each of them is independant, I wanted to create a function that can multiprocess another function. The latter will have arguments, and return a result. Using a shared dictionnary and the lib concurrent.futures, I managed to write this : import concurrent.futures as Cfut def multiprocess_loop_grouped(function,

Why is asyncio.Future incompatible with concurrent.futures.Future?

旧巷老猫 提交于 2019-12-22 03:44:46
问题 The two classes represent excellent abstractions for concurrent programming, so it's a bit disconcerting that they don't support the same API. Specifically, according to the docs: asyncio.Future is almost compatible with concurrent.futures.Future . Differences: result() and exception() do not take a timeout argument and raise an exception when the future isn’t done yet. Callbacks registered with add_done_callback() are always called via the event loop's call_soon_threadsafe() . This class is

Scala Futures: Default error handler for every new created, or mapped exception

为君一笑 提交于 2019-12-19 22:10:32
问题 Is there any possibility to always create a Future{...} block with an default onFailure handler? (e.g. write the stacktrace to the console)? This handler should also be automatically attached to mapped futures (new futures created by calling map on an future already having a default failure handler) See also my question here for more details: Scala on Android with scala.concurrent.Future do not report exception on system err/out I want to have a "last resort" exception logging code, if

CompletableFuture is not getting executed. If I use the ExecutorService pool its work as expected but not with the default forkJoin common pool

拜拜、爱过 提交于 2019-12-18 05:06:16
问题 I am trying to run the following class its getting terminated without executing the CompletableFuture. public class ThenApplyExample { public static void main(String[] args) throws Exception { //ExecutorService es = Executors.newCachedThreadPool(); CompletableFuture<Student> studentCompletableFuture = CompletableFuture.supplyAsync(() -> { try { TimeUnit.SECONDS.sleep(2); } catch (InterruptedException e) { e.printStackTrace(); } return 3; })// If I put executorservice created n commented above

concurrent.futures issue: why only 1 worker?

孤者浪人 提交于 2019-12-12 19:21:41
问题 I am experimenting the use of concurrent.futures.ProcessPoolExecutor to parallelize a serial task. The serial task involves finding the number of occurrence of a given number from a number range. My code is shown below. During its execution, I noticed from Task Manager / System Monitor / top that only one cpu/thread is constantly in operation despite giving the max_workers of processPoolExecutor a value more than 1. Why is this the case? How can I parallelize my code using concurrent.futures?

How to break time.sleep() in a python concurrent.futures

风格不统一 提交于 2019-12-12 08:07:46
问题 I am playing around with concurrent.futures. Currently my future calls time.sleep(secs) . It seems that Future.cancel() does less than I thought. If the future is already executing, then time.sleep() does not get cancel by it. The same for the timeout parameter for wait(). It does not cancel my time.sleep() . How to cancel time.sleep() which gets executed in a concurrent.futures? For testing I use the ThreadPoolExecutor. 回答1: If you submit a function to a ThreadPoolExecutor , the executor

concurrent.futures not parallelizing write

主宰稳场 提交于 2019-12-12 03:24:34
问题 I have a list dataframe_chunk which contains chunks of a very large pandas dataframe.I would like to write every single chunk into a different csv, and to do so in parallel. However, I see the files being written sequentially and I'm not sure why this is the case. Here's the code: import concurrent.futures as cfu def write_chunk_to_file(chunk, fpath): chunk.to_csv(fpath, sep=',', header=False, index=False) pool = cfu.ThreadPoolExecutor(N_CORES) futures = [] for i in range(N_CORES): fpath = '

Parallel compute task to brute-force in python

﹥>﹥吖頭↗ 提交于 2019-12-12 03:22:41
问题 /* This is not for anything illegal just that my school only uses 7 integers, and I want to see if I can get this to work in time as currently I need 1.59 years to crack a password. The school has it's own private server on site for anyone concerned and it's easily detectable. I'll do this only to me or my friends with their permission .*/ I just wanted to use multi processing or concurrent.futures to make this password cracker run in reasonable time. Here is my attempt at paralleling it

Send SIGTERM to the running task, dask distributed

别等时光非礼了梦想. 提交于 2019-12-12 01:13:13
问题 When I submit a small Tensorflow training as a single task, it launches additional threads. When I press Ctrl+C and raise KeyboardInterrupt my task is closed but underlying threads are not cleaned up and training continues. Initially, I was thinking that this is a problem of Tensorflow (not cleaning threads), but after testing, I understand that a problem comes from the Dask side, that probably doesn't populate SIGTERM signal further to the task function. My question, how can I set Dask to