socket and subprocess problem

Bryan Olson fakeaddress at
Tue Dec 16 04:12:06 CET 2008

goatold at wrote:
> 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
> ().

Looks like a race. The first process tries to connect before the 
external program gets through socket.listen(). If you think about it, 
it's not that surprising.

> But if I run my subprocess.Popen code and socket code in two separate
> python process. Socket will connect just fine.

It's still a race condition even if the side you want to win almost 
always does.


More information about the Python-list mailing list