socket and subprocess problem

goatold at gmail.com goatold at gmail.com
Tue Dec 16 03:46:55 CET 2008


Hi all,

Here is my problem, see if any one else met this before
In my python code I use subprocess.Popen to run and external program
who will listen to a TCP port. And I also create a socket to connect
to the TCP port that the external program is listening.
I will get 'Connection refused, errno=111' when I try to socket.connect
().
But if I run my subprocess.Popen code and socket code in two separate
python process. Socket will connect just fine. OS is RHEL5 x86_64,
python version is 2.6.1 Pseudo code as below


Class a:
  def run()
    subprocess.Popen(..)
Class b:
  def run():
    sock = socket.socket()
    sock.connect(..)
#################################
test.py
# socket connect will fail here
a.run()
b.run()
###################################
test1.py
if __name__ = '__main__':
  a.run()

test2.py
# socket will connect fine
if __name__ = '__main__':
  b.run



More information about the Python-list mailing list