Passing Python socket objects to child processes in Windows

Discussion in 'Python' started by dan.jakubiec@gmail.com, Jan 23, 2007.

  1. Guest

    I'm trying to write a Python app which accepts a socket connection and
    then spawns another Python process to handle it. I need it to run
    under both Linux and Windows. I have it working under Linux, but am
    having problems with the Windows implementation.

    My app uses the subprocess.Popen class to spawn the child process. The
    first problem I ran into was that Windows Python won't let you pass a
    socket object via the Popen stdin argument (it results in a "bad file
    descriptor" error). File object work okay, but sockets seem to be
    handled differently.

    After some searching, I found something of a work-around in this post:
    http://mail.python.org/pipermail/python-list/2004-October/287742.html.

    This workaround uses pywin32 to duplicate the original socket handle
    via the Win32 API. It almost works, in the sense that I now have a
    file stream in my child process which corresponds to the original
    socket object in the parent. But I can't find a way to convert the
    resulting Windows file handle into a Python socket object (there does
    not appear to be a Windows-equivalent of the socket.fromfd() function).
    My app needs the socket object in order to control TCP stuff.

    So I'm a bit stuck. Is there a better way (or any way?) to pass a
    socket to a child process in Windows, and to actually end up with a
    Python socket object in the child process?

    Thanks in advance for any help.

    --
    Dan Jakubiec
    , Jan 23, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Rodriguez
    Replies:
    23
    Views:
    1,114
    David Schwartz
    Dec 9, 2003
  2. Replies:
    0
    Views:
    321
  3. Laszlo Nagy
    Replies:
    1
    Views:
    4,816
    Mark Wooding
    Jan 27, 2009
  4. Sonny Chee
    Replies:
    3
    Views:
    91
    Joel VanderWerf
    Feb 6, 2007
  5. Replies:
    1
    Views:
    248
Loading...

Share This Page