itxx00 / pypcap

Automatically exported from code.google.com/p/pypcap
Other
0 stars 0 forks source link

libpcap thread safety with pythoncom #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I've encountered a thread safety problem with pcap after importing the
pythoncom module in a separate thread. The code below exemplifies this
behavior. Here, the Debug Thread is locked in the pcap.pcap method, so you
never see the "PCap call successful" printout. On the other hand, if the
pythoncom module is imported in the Debug Thread (uncomment the import
statement at line 14 and comment out line 2), the code executes with no
problem. Anyone have any ideas?

Im currently running:
python 2.5.2
pcap-1.1.win32-py2.5
pywin32-210.win32-py2.5
WinPcap 4.0.2

-------------------------------------
import pcap
import pythoncom
import threading
import imp

def main():
t = threading.Thread(name="Debug Thread", target=_launchpcap)
t.start()
t.join()
print "Debug Thread complete!"

def _launchpcap():
print "Debug Thread starting..."
ins = pcap.pcap(name="eth1", snaplen=1600, promisc=1, timeout_ms=500)
print "PCap call successful!"

if __name__ == "__main__":
main()

Original issue reported on code.google.com by parks.jo...@gmail.com on 7 May 2009 at 4:27

GoogleCodeExporter commented 9 years ago
may be it's not about pythoncom,just about the pcap. 
I just change the pcap.pcap call's first parameter to a real network interface 
,not the
\\Device\\NPF_GenericDialupAdapter, the code will work ok. and i think the eth1 
in windows is not correct. ethx only for linux

below is my computer interface ,you can use the findalldevs to get all of them.
devs=pcap.findalldevs()
print devs

['\\Device\\NPF_GenericDialupAdapter', '\\Device\\NPF_{6D07FB9F-1370-4F23-A5D3-B
4F5F490CC0C}', '\\Device\\NPF_{773A9714-E74C-40DF-87BD-70130934E3DB}']

Original comment by xueyaos...@gmail.com on 14 Oct 2010 at 6:02