Results 1 to 6 of 6

Thread: Python Programming Question

  1. #1
    Join Date
    Jan 2009
    Location
    Virginia, USA
    Beans
    12
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Python Programming Question

    Hey!

    I am learning python slowly but surely and was wondering how you would execute another program (like handbrake) in the background of a computer (so that the python application does not wait for handbrake to finish, and then you can check on the status of handbrake running whenever. Is that possible?

  2. #2
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: Python Programming Question

    That sounds to multithreading... it's a really hard topic, as far as I heard (I never did it either...).

  3. #3
    Join Date
    Feb 2009
    Beans
    72

    Re: Python Programming Question

    I've never used multithreading in Python, but in C it's easy.

    The relevent doc page for Python appears to be:

    http://docs.python.org/3.0/library/m...multithreading

  4. #4
    Join Date
    Jul 2008
    Beans
    1,706

    Re: Python Programming Question

    Quote Originally Posted by nvteighen View Post
    That sounds to multithreading... it's a really hard topic, as far as I heard (I never did it either...).
    depends on the language...

    i advise reading this and using the os.system() method to call the other program

  5. #5
    Join Date
    Jun 2007
    Beans
    692

    Re: Python Programming Question

    I think you want the subprocess module, and the subprocess.Popen class specifically. It lets you spawn a non-blocking child process and check its pid/return code (if it's finished running)/etc.

    edit: See the documentation here: http://docs.python.org/library/subprocess.html

    edit edit: In the simplest case, you would use it like this:
    PHP Code:
    import subprocess
    import time

    pobj 
    subprocess.Popen("ls")
    while 
    pobj.poll() is None:
        print 
    "ls is still running"
        
    time.sleep(3)
    print 
    "ls return code is %s" pobj.poll() 
    Last edited by imdano; February 17th, 2009 at 10:31 PM.

  6. #6
    Join Date
    Jan 2009
    Location
    Virginia, USA
    Beans
    12
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Python Programming Question

    Thanks, yeah that is what I was looking for, I have been playing with that a little, and yours seems to tell me what to do.


    Quote Originally Posted by imdano View Post
    I think you want the subprocess module, and the subprocess.Popen class specifically. It lets you spawn a non-blocking child process and check its pid/return code (if it's finished running)/etc.

    edit: See the documentation here: http://docs.python.org/library/subprocess.html

    edit edit: In the simplest case, you would use it like this:
    PHP Code:
    import subprocess
    import time

    pobj 
    subprocess.Popen("ls")
    while 
    pobj.poll() is None:
        print 
    "ls is still running"
        
    time.sleep(3)
    print 
    "ls return code is %s" pobj.poll() 

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •