How can I know when a sub-process is effectively initialized?

Giampaolo Rodola' gnewsg at gmail.com
Thu Feb 26 15:27:26 EST 2009


Hi,
I'm working on a Python module called psutil [1] for reading process
information in a cross-platform way.
I'm having a problem with psutil test suite.
Almost all the test cases we implemented so far look like this:

def test_foo(self):
    test_process = subprocess.Popen(sys.executable, stdout=DEVNULL,
stderr=DEVNULL)
    time.sleep(0.1)  # XXX: provisional, give some time the sub
process to initialize
    p = psutil.Process(test_process.pid)
    # start test here
    ...

As you can see we put a time.sleep(0.1) call after subprocess.Popen()
as a provisional workaround to let the sub process initialize
properly.
We're searching for some kind of way to know when the child process is
properly initialized so that we can actually start testing cases
without worries.
Does someone has an idea how could we do that?

[1] http://code.google.com/p/psutil/

Thanks a lot in advance,



--- Giampaolo
[1] http://code.google.com/p/pyftpdlib



More information about the Python-list mailing list