473,386 Members | 1,621 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,386 software developers and data experts.

Python I.P.C

Basically, I have two python processes, a client and a server.
They are communicating via a socket. If the client can't connect to
the server, it starts a new server process, and has to wait until the
server is up and listening for requests on the socket. Can anyone
recommend a good way for the client to block until the server is ready
to do business?

Thanks
Dan
Jul 18 '05 #1
2 4153
Daniel Greenblatt wrote:
Basically, I have two python processes, a client and a server.
They are communicating via a socket. If the client can't connect to
the server, it starts a new server process, and has to wait until the
server is up and listening for requests on the socket. Can anyone
recommend a good way for the client to block until the server is ready
to do business?

My recommendation: spawn the server, then sleep for a second, try to
connect, sleep, try to connect, ad connectionem. It's simple, easy,
effective, robust, and most importantly, doesn't needlessly complicate
the server process.
But if you'd rather do it the hard way, probably the most straight-
forward way (in Unix) is to have the server send a signal (say,
SIGUSR1) to the client when it's ready, and have the client wait for
the signal.

Another possibility is to have the client open a pipe for reading,
passing the writing end to the server. Have the server output
something (say, the string "READY") through the pipe when it's ready.
The client can wait for this string on its end. I don't recommend
that, though, because it's a common and useful practice for a daemon
to close all open file descriptors when starting up.

See the Unix Programmer FAQ for details:
http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16

One other thing to keep in mind: there is a race condition here.
Suppose a second clients starts up after a first clients spawns the
server, but before the server is initialized. The second client would
also attempt to start the server, but (I think) that server will not
be able to listen to the same port. If you don't take care to handle
this properly, it might leave the second client waiting for a signal
that'll never come.
--
CARL BANKS http://www.aerojockey.com/software

As the newest Lady Turnpot descended into the kitchen wrapped only in
her celery-green dressing gown, her creamy bosom rising and falling
like a temperamental souffle, her tart mouth pursed in distaste, the
sous-chef whispered to the scullery boy, "I don't know what to make of
her."
--Laurel Fortuner, Montendre, France
1992 Bulwer-Lytton Fiction Contest Winner
Jul 18 '05 #2
Daniel Greenblatt wrote:
Basically, I have two python processes, a client and a server.
They are communicating via a socket. If the client can't connect to
the server, it starts a new server process, and has to wait until the
server is up and listening for requests on the socket. Can anyone
recommend a good way for the client to block until the server is ready
to do business?


Create a server socket in the client, spawn the server (pass the socket
port), then listen on the server socket until the server connects to it.

The you can remove this socket and start the regular program.

Daniel

Jul 18 '05 #3

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

Similar topics

0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.