Skip to content

Instantly share code, notes, and snippets.

@danwald
Created June 17, 2025 16:38
Show Gist options
  • Select an option

  • Save danwald/f95206e970a111c199a8db1c4b9f51a3 to your computer and use it in GitHub Desktop.

Select an option

Save danwald/f95206e970a111c199a8db1c4b9f51a3 to your computer and use it in GitHub Desktop.
import threading
import time
from concurrent.futures import ProcessPoolExecutor
lock = threading.Lock()
def process_items(name):
lock_id = id(lock)
print(f"{name}: acquiring lock:{lock_id}")
with lock:
print(f"{name}: has lock:{lock_id}")
time.sleep(10)
print(f"{name}: released lock:{lock_id}")
if __name__ == "__main__":
t = threading.Thread(target=process_items, args=("Thread",))
t.start()
time.sleep(2)
with ProcessPoolExecutor() as e:
e.submit(process_items, "Process")
@danwald
Copy link
Author

danwald commented Jun 18, 2025

only on linux .. python:3.12-alpine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment