pylibpcap and multiple threads

Carlos Ribeiro carribeiro at gmail.com
Mon Jan 24 21:19:07 EST 2005


On Mon, 24 Jan 2005 15:18:39 +0100, Örjan Gustavsson
<orjan at switchcore.com> wrote:
> Hi All!
> 
> Sorry if this is not the correct forum for this kind of question (I did
> not find any pylibpcap related lists).
> 
> I am trying to use pylibpcap to capture network traffic from several
> ethernet devices at the same time, each nic having a separate thread
> assigned to it.
> 
> My problem is that when one thread is blocking inside pcap.loop() for
> instance, it seems to have acquired the GIL, so that no other threads
> can run.
> 
> Does anyone know a way to do this with threads, or is the only way to
> have separate processes for each NIC?

>From the top of my head, and without any test. I did use libpcap for
some stuff recently. loop() is the primitive that keeps reading and
calls the callback, right? I believe that it should release the GIL in
the C wrapper code, right before calling the libpcap loop
implementation, and re-acquire it before calling the callback. There
is a standard way to do it, that is used before blocking calls are
issued (file writing, for example). If it fails to release the GIL it
will block.

I'm also not sure if the libpcap itself is supposed to be used this
way - with multiple instances - but I assume that it should work (I
never tried to open several instances of tcpdump at the same time).

Also, check these links also, as they may be helpful to you:

http://libdnet.sourceforge.net/
http://oss.coresecurity.com/projects/pcapy.html

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list