[Pyrex] Pyrex Digest, Vol 57, Issue 1

Claudio Freire klaussfreire at gmail.com
Sat Sep 26 18:59:16 CEST 2009


On Sat, Sep 26, 2009 at 7:00 AM, <pyrex-request at lists.copyleft.no> wrote:

>        while 1:
>            Py_BEGIN_ALLOW_THREADS
>            n = pcap_ex_next(self.__pcap, &hdr, &pkt)
>            Py_END_ALLOW_THREADS
>            self._hdr = hdr
>            self._pkt = pkt
>            if n == 1:
>                return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0),
>                        PyBuffer_FromMemory(pkt, hdr.caplen))
>            elif n == -1:
>                raise KeyboardInterrupt
>            elif n == -2:
>                raise StopIteration
>
>
> the problem is with a timeout. basically it doesn't work. it waits
> till a packet arrive.
>

Doesn't that code need an 'if n == 0: break' (or similar) ?
Otherwise it will retake the GIL when the timeout happens, and immediately
release it again and wait for a second timeout period, and third... and so
on. See, the while 1.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.copyleft.no/pipermail/pyrex/attachments/20090926/ba227bf7/attachment.html>


More information about the Pyrex mailing list