threading and signals - main thread solely responsible for signal handling?
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? -- http://mail.python.org/mailman/listinfo/python-list
convert n-byte string into integer
Hello there. Since this is one of those problems that may have some painfully simple solution that will make me feel like a fool, I'll start of with this: it's _very_ late (.. yeah, it's not). To the point. Data returned by socket.recvfrom is a string. Obviously one that most of the time will contain non-printable characters. Let's say data[10:14] is a four byte integer. How can I convert the string data[10:14] to a python integer object? Or perhaps there's a totally different, *Pythonic*, approach to this (extracting data from these packet-representing strings). C may have poisoned my mind. Thanks for reading, hoping for some ideas. -- http://mail.python.org/mailman/listinfo/python-list
Re: convert n-byte string into integer
On Apr 28, 11:03 pm, MRAB wrote: > Maligree wrote: > > Hello there. > > > Since this is one of those problems that may have some painfully > > simple solution that will make me feel like a fool, I'll start of with > > this: it's _very_ late (.. yeah, it's not). > > > To the point. > > > Data returned by socket.recvfrom is a string. Obviously one that most > > of the time will contain non-printable characters. Let's say > > data[10:14] is a four byte integer. How can I convert the string > > data[10:14] to a python integer object? > > > Or perhaps there's a totally different, *Pythonic*, approach to this > > (extracting data from these packet-representing strings). C may have > > poisoned my mind. > > > Thanks for reading, hoping for some ideas. > > Use the 'unpack' function from the 'struct' module. Ah, thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
