trouble with sys.exec and sockets/ssh

Richard Cook rcook at
Fri Feb 21 22:48:48 CET 2003

At 7:52 PM +0000 2/21/03, Donn Cave wrote:
>Quoth Richard Cook <rcook at>:
>| I have a problem as follows.  I call an executable with os.execv(cmd,
>| args) and it launches fine.  However, it then misbehaves.  The normal
>| behavior of the program is to fork off children, each of which execs
>| another process (ssh), which creates a process on a remote machine,
>| which connects back to the main process using a socket connection
>| over TCP/IP or UDP.  This works fine every time from the shell
>| command line.  But it fails from my python script.  The behavior when
>| I fork it off using os.execv in python is that the socket connections
>| back "home" from the children fail. Not all of them fail, just many
>| of them.  (If any fail, it's a disaster for me.)  Clearly the
>| environment that the process I execv from python sees is somehow
>| different than that seen by the same process if I run it from the
>| shell.  Can anyone guess as to what I'm doing wrong or not
>| understanding?  Thank you.
>What does "the socket connections ... fail" mean?   They abort
>with "Connection refused" errors?
>I don't really have much of a clue, and you may have to post an
>example program before anyone sees the problem.  But one thing
>you might try is a little delay - put a time.sleep(1.0) between
>the forks, the real idea being to stagger the incoming connections
>a little.  If that helps but isn't attractive, you might be able
>to deal with the problem by increasing the listen() value.

I knew this question would cause confusion.  Here is my example program:

import os
os.execv('ensight7.sos', 'ensight7.sos', '-c', '')

That's it.  I don't have control over how ensight7.sos forks its 
children.  I don't do any forking in my program.  When I run
ensight7.sos -c
from the command line, it works fine.  It spawns remote processes 
which connect back to itself just fine.  But when I launch it from 
python with os.execv, it does not work.  It's as if the "socket 
environment" is different for things exec'd from a pythong script.
Does python modify its environment in any way when it launches?
Richard Cook  
Lawrence Livermore National Laboratory
Bldg-451 Rm-2043, Mail Stop L-561       
7000 East Avenue,  Livermore, CA, 94550, USA
phone (925) 423-9605 (work)    fax (925) 423-8704
Information Management & Graphics Grp., Services & Development Div., 
Integrated Computing & Communications Dept.
(opinions expressed herein are mine and not those of LLNL)

More information about the Python-list mailing list