Skip to content

[Question] Best practice to get an event when server is up #7

Answered by jaraco
mar10 asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry for the delay in response.

The way I deal with this sort of situation in general is to avoid interprocess communication altogether and rely on the socket communication to wait on server to bind to the port. For that, I use portend. This approach allows me to disregard the implementation details of a given service.

port = portend.find_available_local_port()
server.start(port)
portend.occupied('::1', port, timeout=5)
# optionally also check a known HTTP status
status_url = 'http://localhost:{port}/server/responding'.format_map(locals())
requests.get(status_url).raise_for_status()

I recognize that interprocess communication may be more elegant and responsive than to poll a port and ti…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by webknjaz

This comment has been hidden.

This comment has been hidden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #7 on September 17, 2020 23:42.