Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8364145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:21:44+00:00 2026-06-09T12:21:44+00:00

test1.py: process = Popen([python,test2.py]) time.sleep(3) alive = process.poll() if alive is None: print Still

  • 0

test1.py:

process = Popen(["python","test2.py"])
time.sleep(3)

alive = process.poll()
if alive is None:
    print "Still running"
else:
    print "Not running\r\n"
    print "%r" % alive

test1.py Output:

Not running
2

test2.py:

time.sleep(30)
print "done"

What is going on? Shouldn’t this return “Still running”?


Because of a contradicting result here’s the full test1.py code:

import cStringIO
import os
import cgi
import time
from subprocess import Popen

def application(environ, start_response):
    headers = []
    headers.append(('Content-Type', 'text/plain'))
    write = start_response('200 OK', headers)

    input = environ['wsgi.input']
    output = cStringIO.StringIO()

    process = Popen(["python","test2.py"])
    time.sleep(3)

    alive = process.poll()
    if alive is None:
        print >> output, "Still running"
    else:
        print >> output, "Not running\r\n"
        print >> output, "%r" % alive

    output.write(input.read(int(environ.get('CONTENT_LENGTH', '0'))))
    return [output.getvalue()]

Updated test1.py:

process = Popen(["python","C:/wamp/www/python/popen/test2.py"], shell=True)
    time.sleep(5)

    alive = process.poll()
    if alive is None:
        #print >> output, "%r" % alive
        print >> output, "Still running"
    else:
        print >> output, "Not running"
        print >> output, "%r" % alive
        print >> output, "Current working dir : %s" % os.getcwd()
        print >> output, os.strerror(0)

Updated Output:

Not running
0
Current working dir : C:\wamp\bin\apache\apache2.2.22
No error

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:21:46+00:00Added an answer on June 9, 2026 at 12:21 pm

    If Popen() cannot find test2.py, it produces the error “No such file or directory”, with errno 2. This error number is returned by poll(). Since you seem to be running this script through wsgi, something seems to be gulping your stderr and you don’t see the error message:

    $ cat test1.py
    from subprocess import Popen
    import time
    
    process = Popen(["python","doesnotexist.py"])
    time.sleep(3)
    
    alive = process.poll()
    if alive is None:
        print "Still running"
    else:
        print "Not running\r\n"
        print "%r" % alive
    $ python test1.py 
    python: can't open file 'doesnotexist.py': [Errno 2] No such file or directory
    Not running
    
    2
    

    Now, the issue is probably because your current working directory of your script is not set to the script’s directory by the front end server, try printing os.getcwd() to see if it’s what you’re expecting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting to implement a poor man's test of whether a process is still running
Is there a way to specify the running directory of command in Python's subprocess.Popen()
i have created a running process which listens for input: listen = Popen([home/user/listen], stdout=PIPE,
I tried these two methods: os.system(python test.py) subprocess.Popen(python test.py, shell=True) Both approaches need to
Here's my main file: import subprocess, time pipe = subprocess.PIPE popen = subprocess.Popen('pythonw -uB
I have a Python program that uses Popen to call a test C++ program.
I'm executing a SSH process like so: checkIn() sshproc = subprocess.Popen([command], shell=True) exit =
test1.py import cStringIO import os import cgi import time import sys from subprocess import
I have a python daemon process that gets started via rc.local. This same script,
I am currently in the process of updating many test sites on an old

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.