Questions tagged [concurrent.futures]

concurrent.futures is a Python module which provides a high-level interface for asynchronously executing callables.

The concurrent.futures module aims to provide a simple interface for parallelizing operations in multi-threaded and multi-process Python applications. The module was added to the Python standard library in version 3.2, but a backport is available for Python 2.5+.

929 questions
-1
votes
1 answer

How do I make this thread safe?

is this thread Safe? I keep getting different results every time I'm not sure how to make this thread safe. My goal is to compute the amount of primes starting from 5 -10000 but doing this using a thread for each computation. I would like to keep…
-1
votes
1 answer

Code is running in VS Code but not in Terminal

My python script is perfectly running in vs code, but when I run it via terminal I get the error message "ImportError: No module named concurrent.futures" I use a venv and a pip list shows: Package Version --------------…
GePlusE
  • 13
  • 10
-1
votes
1 answer

Python multiprocessing shared variables

I'm trying to share the class instance/object variables with other processes that I start within it, since I need to run multiple function at the same time, to record macros from the keyboard & mouse and re-play them latter at the same timing. I see…
-1
votes
1 answer

Weird behavior in ProcessPoolExecutor from concurrent.futures library

In the below code, the print happens once per processes including the main process, for as shown in the example I have 2 processes and the statement is printed 3 times. I expected it to run only once since every subprocess should only execute the…
-1
votes
1 answer

processsing each element of dictionary of lists using concurrent.futures.ThreadPoolExecutor

suppose i have a dictionary such as dict = {A:[1,2,3], B:[4,5,6], C:[7,8,9], ......} I want to process each element of a particular key's list one after other but the individual keys could be processed in parallel using…
-1
votes
1 answer

python speedup a simple function

I try to find a simple way to "speed up" simple functions for a big script so I googled for it and found 3 ways to do that. but it seems the time they need is always the same. so what I am doing wrong testing them? file1: from concurrent.futures…
-1
votes
1 answer

Trouble in Optimizing asyncio with concurrent futures

I'm trying to run asyncio task concurrently on each worker thread of concurrent.futures Threadpool. However, I couldn't achieve the desired outcome. async def say_after(delay, message): logging.info(f"{message} received") await…
-1
votes
2 answers

make scala future wait to modify a variable

I have been struck with a piece on how to obtain a listbuffer of strings in the case where the listbuffer happens to be constructed in a scala future called in a loop. Here is a kiss example def INeedThatListBuffer(): ListBuffer[String] = { var…
sdinesh94
  • 1,138
  • 15
  • 32
-1
votes
1 answer

Python request futures does not seem to be working for me

I have the following piece of code import concurrent.futures as cf from requests_futures.sessions import FuturesSession urls = ['http://www.foxnews.com/', 'http://www.cnn.com/', 'http://europe.wsj.com/', …
user3249433
  • 591
  • 3
  • 9
  • 18
-2
votes
1 answer

Python thread pool executor gets slower over time for I/O bound tasks

I use a threading pool executor to run a function over a large number of endpoints. What I do not understand is that it is getting slower over time - e.g. initially it processes 5-6000 urls in the monitoring "refresh" interval, but this number keeps…
-2
votes
1 answer

threadpool executor inside processpoolexecutor RuntimeError: There is no current event loop in thread

I have a processpoolexecutor into which I submit multiple disk read/write calls. I want to create a threadpool inside every process for performance benefits. below is my attempt to override and modify _process_worker method of concurrent.futures…
CodeTry
  • 312
  • 1
  • 19
-2
votes
2 answers

How to pass function output in futures and then those futures to a new function?

My Scenario is like below: Step1: x =def sum(a,b) Step2: Thread.sleep(1s) Step3: y =def subtract(a,b) Step4: Thread.sleep(2s) Step5: On successfull completion of above steps perform z = multiple(x,y) I need to implement this scenario using futures…
-2
votes
1 answer

Parallelize this code

I am trying to figure out how to parallelize the following code. I have looked up joblib, concurrent.futures, and multiprocessing modules, but cannot for the life of me figure out how they work from reading the docs and scouring SO/google. Grid is a…
-3
votes
1 answer

Scala boolean always returning false

I was wondering why the following function doesMsgExist() always returns false even when the results from the DB is not empty. def doesMsgExist(name: String, age: String): Boolean = { var result = false val msgExistsFlag =…
summerNight
  • 1,446
  • 3
  • 25
  • 52
1 2 3
61
62