socket's strange behavior with subprocesses

Jane Austine janeaustine50 at
Thu Nov 13 01:46:32 CET 2003

"Colin Brown" <cbrown at> wrote in message news:<3fb28c56$1 at>...
> "Jane Austine" <janeaustine50 at> wrote in message
> news:ba1e306f.0311120837.6e6eddf2 at
> > Running Python 2.3 on Win XP
> >
> > It seems like socket is working interdependently with subprocesses of
> > the process which created socket.
> > and the server side tries to close the socket:
>  .....
> > Alas, the client side doesn't wake up! It doesn't wake up unless the
> > notepad is exited first; only after that, 'Connection reset by peer'
> > is raised. What does the socket has to do with subprocesses?
> Hi Jane
> I think it may be tied up with the way subprocesses are made under Windows.
> Below is a copy of part of a post I made some months back when inexplicable
> file-locking was causing me problems. It took me weeks to track down the
> reason.
> The Python default subprocess inherits open handles from the parent.
> Your options are:
> 1. Open the subprocess before the socket.
> 2. Create the subprocess using win32 API primitives (this is what I had to
> do).
>     Let me know if want details.
> Colin Brown
> PyNZ

Thank you very much, first of all.

I tried win32 API primitives for creating subprocesses: win32all's
CreateProcess. I used the Process class in in the
"demos" directory. However, it didn't work with sockets perfectly.

Say, a socket server python script is launched via CreateProcess. It
then launches sub-processes. And I kill(via TerminateProcess) the
socket server process. The subprocesses remain alive(as expected). I
try to connect to the 'dead server port'. I expect almost immediate
"connect refused" error, but it doesn't come up until the subprocesses
are all gone and client hangs forever.


More information about the Python-list mailing list