Need to create subprocess...

Discussion in 'Python' started by drstoka, Mar 18, 2010.

  1. drstoka

    drstoka Guest

    Hello,

    I have to run a program as a child process inside my python program and
    redirect it's output through a pipe to a parent program process.
    So, I wrote this:

    pipe = Popen('example_program', shell=True, bufsize=0, stdout=PIPE).stdout

    and it works great.

    Now, in parent program I need to wait for a some time and if a child
    (example_program) does not finish in that time, kill the child.

    How do I do that? Please help.
     
    drstoka, Mar 18, 2010
    #1
    1. Advertising

  2. On 03/18/10 16:17, drstoka wrote:
    > Hello,
    >
    > I have to run a program as a child process inside my python program and
    > redirect it's output through a pipe to a parent program process.
    > So, I wrote this:
    >
    > pipe = Popen('example_program', shell=True, bufsize=0, stdout=PIPE).stdout
    >
    > and it works great.
    >
    > Now, in parent program I need to wait for a some time and if a child
    > (example_program) does not finish in that time, kill the child.
    >
    > How do I do that? Please help.
    >
    >

    Try searching around for "threading.thread python" it should give you
    some clues, if you can't work through the info (it can be a bit hard to
    digest), just post here an example of your test code along with what you
    expected and what didn't happen.

    --
    mph
     
    Martin P. Hellwig, Mar 18, 2010
    #2
    1. Advertising

  3. On Mar 18, 11:17 am, "drstoka" <>
    wrote:
    > Hello,
    >
    > I have to run a program as a child process inside my python program and
    > redirect it's output through a pipe to a parent program process.
    > So, I wrote this:
    >
    > pipe = Popen('example_program', shell=True, bufsize=0, stdout=PIPE).stdout
    >
    > and it works great.
    >
    > Now, in parent program I need to wait for a some time and if a child
    > (example_program) does not finish in that time, kill the child.
    >
    > How do I do that? Please help.


    I have a module that does this and more, but it only works on Linux:

    http://code.google.com/p/rst2pdf/source/browse/trunk/rst2pdf/tests/execmgr.py

    For usage examples, you can just execute it. Also, see autotest.py in
    the same directory.

    Regards,
    Pat
     
    Patrick Maupin, Mar 18, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    543
    Nicola Musatti
    Jun 6, 2008
  2. gb345
    Replies:
    4
    Views:
    304
    gb345
    Oct 10, 2009
  3. hiral
    Replies:
    2
    Views:
    632
    Jean-Michel Pichavant
    May 5, 2010
  4. Muffinman

    Create subprocess (two distinct processes)

    Muffinman, Nov 28, 2012, in forum: C Programming
    Replies:
    8
    Views:
    314
    Jorgen Grahn
    Dec 5, 2012
  5. Piotr Dobrogost
    Replies:
    0
    Views:
    99
    Piotr Dobrogost
    Mar 4, 2013
Loading...

Share This Page