concurrent.futures

Is having a concurrent.futures.ThreadPoolExecutor call dangerous in a FastAPI endpoint?

Is having a concurrent.futures.ThreadPoolExecutor call dangerous in a FastAPI endpoint? Question: I have the following test code: import concurrent.futures import urllib.request URLS = [‘http://www.foxnews.com/’, ‘http://www.cnn.com/’, ‘http://europe.wsj.com/’, ‘http://www.bbc.co.uk/’, ‘http://some-made-up-domain.com/’] # Retrieve a single page and report the URL and contents def load_url(url, timeout): with urllib.request.urlopen(url, timeout=timeout) as conn: return conn.read() # We can use a with …

Total answers: 1

Best way to output concurrent task results in shell on the go

Best way to output concurrent task results in shell on the go Question: That is maybe a very basic question, and I can think of solutions, but I wondered if there is a more elegant one I don’t know of (quick googling didn’t bring anything useful). I wrote a script to communicate to a remote …

Total answers: 1

Passing a function that takes **kwargs into concurrent.futures.ThreadPoolExecutor.map

Passing a function that takes **kwargs into concurrent.futures.ThreadPoolExecutor.map Question: I’ve just begun learning concurrent programming in Python. I created a function which takes one positional argument and then **kwargs. Code: def download_from_api(api_client_method, **kwargs): try: response = api_client_method(**kwargs) return response except api.exceptions.APIException as e: print(f'{kwargs}: {api_client_method.__name__} – {e}) I’d like to pass this function to concurrent.futures.ThreadPoolExecutor().map() …

Total answers: 1

Why does a result() from concurrent.futures.as_completed() occasionally return None?

Why does a result() from concurrent.futures.as_completed() occasionally return None? Question: I’ve been writing a fairly complex series of modules to help test our poorly documented networking gear, this one focused on trying the various passwords used across the company. I’ve been using the concurrent.futures module to speed things along by testing many devices in parallel …

Total answers: 1

ProcessPoolExecutor suddenly stops at 255th process

ProcessPoolExecutor suddenly stops at 255th process Question: I’m trying to use concurrent.futures and to increment the process number which is allocated in the shared_memory. (How to properly close and unlink shared memory of multiprocessing?) But, the incrementation suddenly stops at state = 255 in the following code. I want to increment the number up to …

Total answers: 1

waiting for one function to finish before starting another python concurrent

waiting for one function to finish before starting another python concurrent Question: I don’t know if this is possible but i have a tool that make use of the python package concurrent the code looks something like this: import concurrent.futures import time def func1(): #do something def func2(): #do something separate def func3(): time.sleep(10) #do …

Total answers: 1

How to use concurrent.future.wait?

How to use concurrent.future.wait? Question: I’m studying python, here I got some problem on the concurrent.futures.wait() — Here’s the details– I want to make the main process hold until all the child processes completed. So I used wait() to block the main process. But I always got error , please kind help. def child_process(args): pid=os.getpid(); …

Total answers: 1

How to create a continuous stream of Python's concurrent.futures.ProcessPoolExecutor.submits()?

How to create a continuous stream of Python's concurrent.futures.ProcessPoolExecutor.submits()? Question: I am able to submit batches of concurrent.futures.ProcessPoolExecutor.submits() where each batch may contain several submit(). However, I noticed that if each batch of submits consumes a significant about of RAM, there can be quite a bit of RAM usage inefficiencies; need to wait for all …

Total answers: 3

concurrent.futures.ThreadPoolExecutor doesn't print errors

concurrent.futures.ThreadPoolExecutor doesn't print errors Question: I am trying to use concurrent.futures.ThreadPoolExecutor module to run a class method in parallel, the simplified version of my code is pretty much the following: class TestClass: def __init__(self, secondsToSleepFor): self.secondsToSleepFor = secondsToSleepFor def testMethodToExecInParallel(self): print("ThreadName: " + threading.currentThread().getName()) print(threading.currentThread().getName() + " is sleeping for " + str(self.secondsToSleepFor) + " …

Total answers: 1

Use tqdm with concurrent.futures?

Use tqdm with concurrent.futures? Question: I have a multithreaded function that I would like a status bar for using tqdm. Is there an easy way to show a status bar with ThreadPoolExecutor? It is the parallelization part that is confusing me. import concurrent.futures def f(x): return f**2 my_iter = range(1000000) def run(f,my_iter): with concurrent.futures.ThreadPoolExecutor() as …

Total answers: 5