Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Passing Python socket objects to child processes in Windows

Reply
Thread Tools

Passing Python socket objects to child processes in Windows

 
 
dan.jakubiec@gmail.com
Guest
Posts: n/a
 
      01-23-2007
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/pyt...er/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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM
Passing user credentials to child processes estadtherr@gmail.com Java 0 09-28-2006 02:43 AM
Child windows can not access window.opener when multiple child windows are open ian.michel@gmail.com Javascript 1 12-14-2004 10:07 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments