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
@benkay86
benkay86 / slurm_sync.py
Last active September 26, 2025 17:11
Synchronizing concurrent slurm jobs using advisory file locks
"""Synchronize slurm jobs using advisory file locks (flock).
This module provides functionality for synchronizing concurrent work across
multiple jobs running on multiple nodes in a slurm cluster. Synchronization is
achieved using advisory file locks, or flock. This module is particularly useful
for easily-parallelizable jobs that divide a large problem into chunks that can
be processed independently.
To use an flock like a mutex:
>>> from slurm_sync import LockFile