{"action":"opened","issue":{"url":"https://api.github.com/repos/pynetwork/pypcap/issues/13","labels_url":"https://api.github.com/repos/pynetwork/pypcap/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/pynetwork/pypcap/issues/13/comments","events_url":"https://api.github.com/repos/pynetwork/pypcap/issues/13/events","html_url":"https://github.com/pynetwork/pypcap/issues/13","id":118926186,"number":13,"title":"Stop pypcap from capturing and writing network traffic to a file","user":{"login":"mbudge","id":15329154,"avatar_url":"https://avatars.githubusercontent.com/u/15329154?v=3","gravatar_id":"","url":"https://api.github.com/users/mbudge","html_url":"https://github.com/mbudge","followers_url":"https://api.github.com/users/mbudge/followers","following_url":"https://api.github.com/users/mbudge/following{/other_user}","gists_url":"https://api.github.com/users/mbudge/gists{/gist_id}","starred_url":"https://api.github.com/users/mbudge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbudge/subscriptions","organizations_url":"https://api.github.com/users/mbudge/orgs","repos_url":"https://api.github.com/users/mbudge/repos","events_url":"https://api.github.com/users/mbudge/events{/privacy}","received_events_url":"https://api.github.com/users/mbudge/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-25T21:22:49Z","updated_at":"2015-11-25T21:22:49Z","closed_at":null,"body":"I'm capturing network traffic with pypcap and writing it to a file with dpkt. Problem is I can't delete the file as I get an error saying it's still in use by another process. I don't want to use scapy as it's not necessary for my project.\r\n\r\n    seconds = 15\r\n    starttime = datetime.datetime.now()\r\n\r\n    pc = pcap.pcap()\r\n    file = open('file.pcap', 'wb')\r\n    pcapfile dpkt.pcap.Writer(file)\r\n\r\n    for timestamp, packet in pc:\r\n        currenttime = datetime.datetime.now()\r\n        timedelta = currenttime - starttime\r\n        if timedelta.seconds > seconds:\r\n            break\r\n\r\n        pcapfile.writepkt(packet,timestamp)\r\n\r\n    file.close\r\n\r\n    time.sleep(10)\r\n\r\n    os.remove(file.pcap) = file in use by another process error\r\n\r\n\r\nI'm currently overwriting the pcap file the next time I capture traffic. Doing this overwrites the file data most of the time, but occasionally it doesn't work and I end up with a large pcap file encompassing two sets of network capture data.  \r\n\r\nHow do you close the pcapy/dpkt process handle?\r\n\r\nAlso does anyone know a better way to stop pcapy capturing traffic after 15 seconds?\r\n\r\nThanks"}}