Re: Pyrex Digest, Vol 57, Issue 1
Claudio Freire <[email protected]> Sat, 26 Sep 2009 13:59:16 -0300
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
--===============0543226367== Content-Type: multipart/alternative; boundary=00c09f971fee282d2904747dfcdc --00c09f971fee282d2904747dfcdc Content-Type: text/plain; charset=ISO-8859-1 On Sat, Sep 26, 2009 at 7:00 AM, <[email protected]> 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. --00c09f971fee282d2904747dfcdc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On Sat, Sep 26, 2009 at 7:00 AM, <span = dir=3D"ltr"><<a href=3D"mailto:[email protected]">pyrex-re= [email protected]</a>></span> wrote:<br><blockquote class=3D"gmail= _quote" style=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt= 0pt 0.8ex; padding-left: 1ex;"> =A0 =A0 =A0=A0 while 1:<br> =A0 =A0 =A0 =A0 =A0 =A0Py_BEGIN_ALLOW_THREADS<br> =A0 =A0 =A0 =A0 =A0 =A0n =3D pcap_ex_next(self.__pcap, &hdr, &pkt)= <br> =A0 =A0 =A0 =A0 =A0 =A0Py_END_ALLOW_THREADS<br> =A0 =A0 =A0 =A0 =A0 =A0self._hdr =3D hdr<br> =A0 =A0 =A0 =A0 =A0 =A0self._pkt =3D pkt<br> =A0 =A0 =A0 =A0 =A0 =A0if n =3D=3D 1:<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1= 000000.0),<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0PyBuffer_FromMemory(pkt, hd= r.caplen))<br> =A0 =A0 =A0 =A0 =A0 =A0elif n =3D=3D -1:<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0raise KeyboardInterrupt<br> =A0 =A0 =A0 =A0 =A0 =A0elif n =3D=3D -2:<br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0raise StopIteration<br> <br> <br> the problem is with a timeout. basically it doesn't work. it waits<br> till a packet arrive.<br></blockquote><div><br>Doesn't that code need a= n 'if n =3D=3D 0: break' (or similar) ?<br>Otherwise it will retake= the GIL when the timeout happens, and immediately release it again and wai= t for a second timeout period, and third... and so on. See, the while 1.<br= > <br></div></div><br> --00c09f971fee282d2904747dfcdc-- --===============0543226367== Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline _______________________________________________ Pyrex mailing list [email protected] http://lists.copyleft.no/mailman/listinfo/pyrex --===============0543226367==--