Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > parallel/concurrent process in python

Reply
Thread Tools

parallel/concurrent process in python

 
 
Ommer.Simjee@gmail.com
Guest
Posts: n/a
 
      03-09-2009
I'm trying to figure out parallel process python code. Something
similar to fork funtion in C.

For example, I using sniff tool in scapy to capture packets but i want
this to run in the background:

-------
from scapy.all import *
import subprocess
import netsnmp

pkts=sniff(iface="eth0",filter="UDP",count=100) # This should run in
the background

print "Next Code."'
---------


"Next Code." should be printed out right away and does not have to
wait for pkts=sniff(...) to finish.

Any ideas?

Thanks,
Ommer S.
 
Reply With Quote
 
 
 
 
Minesh Patel
Guest
Posts: n/a
 
      03-10-2009
On Mon, Mar 9, 2009 at 2:47 PM, <(E-Mail Removed)> wrote:
> I'm trying to figure out parallel process python code. Something
> similar to fork funtion in C.
>
> For example, I using sniff tool in scapy to capture packets but i want
> this to run in the background:
>
> -------
> from scapy.all import *
> import subprocess
> import netsnmp
>
> pkts=sniff(iface="eth0",filter="UDP",count=100) # This should run in
> the background
>
> print "Next Code."'
> ---------
>
>
> "Next Code." should be printed out right away and does not have to
> wait for pkts=sniff(...) to finish.
>
> Any ideas?


Why not use os.fork(), it is the same as C's fork?

if os.fork(): # Returns 0 to child, non-zero to parent
# Do parent stuff
else:
# Do child stuff

--
Thanks,
Minesh Patel
 
Reply With Quote
 
 
 
 
cgoldberg
Guest
Posts: n/a
 
      03-10-2009
> Why not use os.fork(), it is the same as C's fork?

os.fork is not cross platform. It is *nix only. Subprocess runs on
Windows also. The OP never specified his platform.

-Corey
 
Reply With Quote
 
Ommer.Simjee@gmail.com
Guest
Posts: n/a
 
      03-10-2009
On Mar 10, 10:06*am, Minesh Patel <(E-Mail Removed)> wrote:
> On Mon, Mar 9, 2009 at 2:47 PM, *<(E-Mail Removed)> wrote:
> > I'm trying to figure out parallel process python code. Something
> > similar to fork funtion in C.

>
> > For example, I using sniff tool in scapy to capture packets but i want
> > this to run in the background:

>
> > -------
> > from scapy.all import *
> > import subprocess
> > import netsnmp

>
> > pkts=sniff(iface="eth0",filter="UDP",count=100) # This should run in
> > the background

>
> > print "Next Code."'
> > ---------

>
> > "Next Code." should be printed out right away and does not have to
> > wait for pkts=sniff(...) to finish.

>
> > Any ideas?

>
> Why not use os.fork(), it is the same as C's fork?
>
> if os.fork(): # Returns 0 to child, non-zero to parent
> * # Do parent stuff
> else:
> * # Do child stuff
>
> --
> Thanks,
> Minesh Patel


Thanks,It works perfectly.
 
Reply With Quote
 
Minesh Patel
Guest
Posts: n/a
 
      03-10-2009
> os.fork is not cross platform. *It is *nix only. *Subprocess runs on
> Windows also. *The OP never specified his platform.
>


Just out of curiosity, how is one able to replace an os.fork() call
with subprocess and have the child execute multiple statements? I
typically see subprocess used for spawning a shell command, piping,
etc...
--
Thanks,
Minesh Patel
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Process Cannot access file "file_name" because it is being used by another process Rithesh Pai ASP .Net 1 08-22-2005 03:02 PM
(Win32) Timing out a process while reading process' output? rtm Perl 0 09-27-2004 10:06 PM
A process serving application pool 'DefaultAppPool' exceeded time limits during start up. The process id was '216'. jack ASP .Net 0 08-01-2004 09:49 PM
The process cannot access the file because it is being used by another process. Jerry ASP .Net 4 12-15-2003 06:07 PM
Are all the signals read in the process should appear in the sensitivity list of the process? walala VHDL 3 09-09-2003 07:47 AM



Advertisments