Two-threaded program handling signals...

Two-threaded program handling signals...

Post by Mikhail Te » Thu, 08 Jun 2006 04:09:18


Hi!

I have program, that keeps waiting for data to be written to a file (by
another process), then reading and processing it, until it receives a
SIGPIPE. Upon receiving the signal, it is supposed to finish processing the
last chunk of data (if any) and exit.

This was all working fine, until I made the program multi-threaded by adding
another thread. The new thread uses no mutex-es or anything, it is just
a "helper"...

It appeared to keep working, but sometimes the process hangs after receiving
(and acknowledging) the usual SIGPIPE. Attaching a de *** to it and
detaching again wakes the process up -- hours later...

It seems, that this happens when the new thread gets the signal, instead of
the main one. How do I prevent this from happening? Thanks!

I'm using pthreads on FreeBSD-6.1. Thanks!

-mi

--
OMG Pademelons! http://www.yqcomputer.com/
 
 
 

1. threading and signals - main thread solely responsible for signal handling?

2. Signal handler doesn`t handle any signals while main thread is blocked

Hi!
I waste a lot of my time figuring why this snip of code doesn`t work.
And still without any solution ;/
Does anybody know why this handler cannot handle SIGINT signal? What
did I wrong?

Thanks in advance.

#
# CODE
#
import signal
from threading import *

def siginthandler(signum, frame):
global work,cv
print 'terminating...'
cv.acquire()
work = 0
cv.notifyAll ()
cv.release()

work = 1
signal.signal (signal.SIGINT, siginthandler)

print 'wait for SIGINT signal'
cv = Condition ()
cv.acquire()
while work:
print 'waiting...'
cv.wait()
print 'woke up'
cv.release()

print 'terminated'

3. Python 2.3.3 signals, threads & extensions: signal handling problem

4. Python 2.3.3 signals, threads & extensions: signal handling problem[Resolved]

5. Second thread mysteriously blocks when main UI thread handles an e

6. POSIX signal handling versus traditional signal handling

7. threading.Thread vs. signal.signal

8. POSIX signal handling versus traditional signal handling

9. [PATCH] Fix i386 signal handling of NODEFER, should not affect sa_mask (was: Signal handling possibly wrong)

10. [PATCH] Fix i386 signal handling of NODEFER, should not affect sa_mask (was: Signal handling possibly wrong)

11. [comp.programming.threads] How to get the handle of thread who sending a message?

12. how to safely cancel a synchronous signal handling thread?

13. thread behaviour during signal handling

14. signal handling with multiple threads