Re: simple threading.Thread and Semaphores hang
- From: Alain Ketterlin <alain@xxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 06 Dec 2010 14:15:04 +0100
lnenov <lnenov@xxxxxxxxxx> writes:
My application hangs on exit.
I have isoleted this piece of code that reproduces the error: (the
time module is extra and not needed to reproduce)
import threading
import time
def func():
b = threading.Semaphore(value=0)
b.acquire()
This waits for the semaphore to have a positive value. This thread is
blocked (apparently forever, since no other thread has access to the
semaphore).
a = threading.Thread(target=func)
a.start()
time.sleep(2)
quit()
When SystemExit is raised, nothing happens. Python hangs.
Your blocked thread is still around, still waiting for the semaphore.
Your program won't exit while there are non-daemon threads alive.
-- Alain.
.
- References:
- simple threading.Thread and Semaphores hang
- From: lnenov
- simple threading.Thread and Semaphores hang
- Prev by Date: Re: Wanted: slow regexes
- Next by Date: Re: Comparison with False - something I don't understand
- Previous by thread: simple threading.Thread and Semaphores hang
- Index(es):