Skip to content

Instantly share code, notes, and snippets.

View benkay86's full-sized avatar

Benjamin Kay benkay86

View GitHub Profile
@benkay86
benkay86 / asyncio_queue_example.py
Created March 27, 2025 18:28
Fine-Grained Control of Concurrent IO using Python's asyncio.Queue
# Python's asynchronous input-output framework speeds up IO-bound operations
# by allowing your python program to make progress on multiple IO-bound tasks
# concurrently. In this example, we load many neuroimaging data files and
# then perform a compute-intensive operation on each of them. Parallelizing the
# compute-intensive operation is beyond the scope of this tutorial. However,
# we can still get a big speed up by reading multiple files concurrently. While
# the program waits for the operating system to make progress on reading one
# file, it can work on computational transformation of another file.
#
# Loading a file asynchronously is straightforward. Here, we define a helper