concurrency

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

Immediately raise exceptions in concurrent.futures

Immediately raise exceptions in concurrent.futures Question: I run several threads concurrently using concurrent.futures. All of them are necessary to run successfully for the next steps in the code to succeed. While at the end of all processes I can raise any exceptions by running .result(), ideally any exception raised in a single thread would immediately …

Total answers: 2

Correctly catch aiohttp TimeoutError when using asyncio.gather

Correctly catch aiohttp TimeoutError when using asyncio.gather Question: It is my first question here on Stack Overflow so I apologize if I did something stupid or missed something. I am trying to make asynchronous aiohttp GET requests to many api endpoints at a time to check the status of these pages: the result should be …

Total answers: 2

Python asyncio event loop equivalent in Go lang

Python asyncio event loop equivalent in Go lang Question: I use asyncio event loop which is a kind of performing asynchronous/concurrency tasks in Python3.x . Is there any equivalent of asyncio (async/await) or coroutines in Go lang on a thread only? [NOTE]: Not parallelism + concurrency (multiprocessing) pattern. [UPDATE]: Here is an asynchronous event loop …

Total answers: 2

How does concurrent.futures.as_completed work?

How does concurrent.futures.as_completed work? Question: I’m learning about python concurrency and I was introduced with the concept of futures. I read that as_completed() takes an iterable of futures and yields them as they are done. I want to know how it works internally. Is it yielding completed tasks (futures) immediately? A naive approach would be …

Total answers: 1

How to limit concurrency with Python asyncio?

How to limit concurrency with Python asyncio? Question: Let’s assume we have a bunch of links to download and each of the link may take a different amount of time to download. And I’m allowed to download using utmost 3 connections only. Now, I want to ensure that I do this efficiently using asyncio. Here’s …

Total answers: 8

Is set.copy() atomic in Python?

Is set.copy() atomic in Python? Question: Suppose we have an instance variable in a class. class MyClass(object): def __init__(): self.set1 = set() Is the following operation atomic? set_shallow_copy = self.set1.copy() I’ve tried to search around, but the only information I’ve found is that reading instance variables are atomic. (Edit) I tried to decompile the bytecode …

Total answers: 2

python concurrent.futures.ProcessPoolExecutor: Performance of .submit() vs .map()

python concurrent.futures.ProcessPoolExecutor: Performance of .submit() vs .map() Question: I am using concurrent.futures.ProcessPoolExecutor to find the occurrence of a number from a number range. The intent is to investigate the amount of speed-up performance gained from concurrency. To benchmark performance, I have a control – a serial code to perform said task (shown below). I have …

Total answers: 2

How would I go about using concurrent.futures and queues for a real-time scenario?

Use concurrent.futures with new tasks for a real-time scenario Question: It is fairly easy to do parallel work with Python 3’s concurrent.futures module as shown below. with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: future_to = {executor.submit(do_work, input, 60): input for input in dictionary} for future in concurrent.futures.as_completed(future_to): data = future.result() It is also very handy to insert and …

Total answers: 4

alembic db migration concurrently

alembic db migration concurrently Question: I have multiple flask apps connected to the same database backend for high availability purposes. There is a problem when app instances try to migrate database concurrently using alembic! What’s the best way to prevent it? Asked By: Robinho || Source Answers: Alembic does not support simultaneous migration. Your best …

Total answers: 1