Forking dangerous

I am developer/code-reviewer/debugger/bug-fixer/architect/teacher/builder from dubai, uae
Search for a command to run...

I am developer/code-reviewer/debugger/bug-fixer/architect/teacher/builder from dubai, uae
No comments yet. Be the first to comment.
You Should Tell Yourself

A URL shortener is a proxy service that provides a mapping between the short and full representation of a URL. The short URL has the advantage of being small. The service can also provide useful analy

Listening to the Mel Robbins's podcast on regrets was a 'ear'-opener. One can have reqrets of action or inaction. 4 types of reqrets foundation - should've done the work boldness - should've taken t

We need to create a unique ID generator for our high-traffic web application, generating about 10K IDs/second. The IDs can't simply be monotonically increasing integers, which are good for data access
doing + telling

Python 3.14+ now duplicates processes with spawn over fork
spawn duplicates the whole process space
fork clones the process but doesn’t duplicate the thread space
The following deadlocks (on linux, <py3.14)
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(1)
print(f"{name}: released lock:{lock_id}")
if __name__ == "__main__":
t = threading.Thread(target=process_items, args=("Thread",))
t.start()
time.sleep(0.1)
with ProcessPoolExecutor() as e:
e.submit(process_items, "Process")
--- output ---
Thread: acquiring lock:281473428672704
Thread: has lock:281473428672704
Process: acquiring lock:281473428672704
Thread: released lock:281473428672704
Processdeadlocks on a duplicated, lockedThreadwhich isn’t released in it’s memory space
Exercise caution when forking prior to py3.14.
Happy coding!