Created
June 17, 2025 16:38
-
-
Save danwald/f95206e970a111c199a8db1c4b9f51a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
only on linux ..
python:3.12-alpine