call to pypcap in separate thread blocks other threads

D

Dmitry Teslenko

Hello!
I'm making gui gtk application. I'm using pypcap
(http://code.google.com/p/pypcap/) to sniff some network packets.
To avoid gui freezing I put pcap call to another thread.
Pypcap call looks like:

pc = pcap.pcap()
pc.setfilter('tcp')
for ts, pkt in pc:
spkt = str(pkt)
...

Sadly, but this call in another thread blocks gtk gui thread anyway.
If I substitute pcap call with something else separate thread don't block
gui thread.

Using another process instead of thead isn't appropriate.

Thread initialization looks like and takes place before gtk.main():

self.__pcap_thread = threading.Thread(target = self.get_city_from_pcap)
self.__pcap_thread.start()
 
A

aspineux

Hello!
I'm making gui gtk application. I'm using pypcap
(http://code.google.com/p/pypcap/) to sniff some network packets.
To avoid gui freezing I put pcap call to another thread.
Pypcap call looks like:

pc = pcap.pcap()
pc.setfilter('tcp')
for ts, pkt in pc:
        spkt = str(pkt)
        ...

Sadly, but this call in another thread blocks gtk gui thread anyway.
If I substitute pcap call with something else separate thread don't block
gui thread.

Using another process instead of thead isn't appropriate.

Thread initialization looks like and takes place before gtk.main():

self.__pcap_thread = threading.Thread(target = self.get_city_from_pcap)
self.__pcap_thread.start()

Did you try using build-in gtk thread ?

Regards

Alain Spineux | aspineux gmail com
Your email 100% available | http://www.emailgency.com
NTBackup frontend sending mail report | http://www.magikmon.com/mkbackup
 
A

aspineux

No. What makes it different?

It allow you to access to you GTK widgets from your threads (you have
rules to follow to do that).

What are you doing from inside your "pcap" thread ?
 
G

Grant Edwards

I'm making gui gtk application. I'm using pypcap
(http://code.google.com/p/pypcap/) to sniff some network packets.
To avoid gui freezing I put pcap call to another thread.
Pypcap call looks like:

pc = pcap.pcap()
pc.setfilter('tcp')
for ts, pkt in pc:
spkt = str(pkt)
...

Sadly, but this call in another thread blocks gtk gui thread anyway.
If I substitute pcap call with something else separate thread don't block
gui thread.

It sounds like the pcap wrapper code doesn't release the GIL
before making a blocking system call. If that's the case,
you'll have to do some hacking on the C-language extension
module code.
 
D

Dmitry Teslenko

It allow you to access to you GTK widgets from your threads (you have
rules to follow to do that).

What are you doing from inside your "pcap" thread ?

I do this thing:

pc.next() blocks other threads. I visit project page and ppl mention
similar issues. Now I think it's pypcap-related problem and project
page is right place to discuss this issue.
Thanks for support.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top