473,395 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Passing Python socket objects to child processes in Windows

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

Jan 23 '07 #1
0 1816

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pif Paf | last post by:
I am writing programs that will run as TCP servers. Briefly, I want to set up a TCP server on a port in such a way that if another server is already sitting on that port (both servers are Python...
11
by: Mike M | last post by:
Is it possible? In the parent process, I have a socket that binds, listens and then accepts new connections (which creates new sockets in the process). I want to be able to pass some of these new...
0
by: Iker Arizmendi | last post by:
Hello all. I'm trying to get a server process to do the following on both Linux and Windows: 1) Create a socket and bind it to some port number. 2) Use spawnl to create other processes that...
10
by: I. Myself | last post by:
Suppose we spawn a child process with Popen. I'm thinking of an executable file, like a compiled C program. Suppose it is supposed to run for one minute, but it just keeps going and going. Does...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 393 open (+15) / 3315 closed (+17) / 3708 total (+32) Bugs : 908 open (+22) / 5975 closed (+49) / 6883 total (+71) RFE : 223 open...
113
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.