threading and signals - main thread solely responsible for signal handling?
MRAB
python at mrabarnett.plus.com
Sat Feb 13 12:02:53 EST 2010
More information about the Python-list mailing list
Sat Feb 13 12:02:53 EST 2010
- Previous message (by thread): threading and signals - main thread solely responsible for signal handling?
- Next message (by thread): threading and signals - main thread solely responsible for signal handling?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Maligree wrote: > The main part of my script is a function that does many long reads > (urlopen, it's looped). Since I'm hell-bent on employing SIGINFO to > display some stats, I needed to run foo() as a seperate thread to > avoid getting errno 4 (interrupted system call) errors (which occur if > SIGINFO is received while urlopen is setting itself up/waiting for a > response). This does the job, SIGINFO is handled without ever brutally > interrupting urlopen. > > The problem is that after starting foo as a thread, my main thread has > nothing left to do - unless it receives a signal, and I am forced to > keep it in some sort of loop so that ANY signal handling can still > occur. I thought I'd just occupy it with a simple while 1: pass loop > but that, unfortunately, means 100% CPU usage. > > Is there any way I could put the main thread to sleep? Or perhaps my > approach is totally wrong? > The simplest fix is to call time.sleep(seconds) in the loop. Repeated sleeps of 1 second, for example, consume very little CPU time.
- Previous message (by thread): threading and signals - main thread solely responsible for signal handling?
- Next message (by thread): threading and signals - main thread solely responsible for signal handling?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list