Running two separate servers (was Re: venv questions)

Chris Angelico rosuav at gmail.com
Mon Aug 29 23:16:00 EDT 2022


On Tue, 30 Aug 2022 at 12:59, gene heskett <gheskett at shentel.net> wrote:
>
> But that might create another problem. how to differentiate the servers,
> both of which
> will want to use localhost:5000 to serve up their web pages we run
> things with.
>
> Suggested solutions?

This is nothing to do with venvs, so I'm forking the thread.

By far the easiest way to differentiate them is to NOT have them both
on localhost:5000. Depending on how you invoke the servers, you should
be able to find a way to configure one (or both) of them to a
different port; common methods include a "--port" argument, setting
the PORT environment variable, and poking in the code to find the
number 5000 and changing it to some other value.

(Less common methods include poking in ctypes to find the number 5000
and changing it to some other value. Mentioned only because I realise
the alternative interpretation of my previous comment.)

Another method would be to change the "localhost" part. The standard
for IP addresses is that 127.x.y.z means localhost, regardless of what
x, y, and z are; so you could have one of them bind to 127.0.0.2 and
the other to 127.0.0.3, which you could then use in your browser the
same way (http://127.0.0.2:5000/ and http://127.0.0.3:5000/
respectively).

But if you can't change anything else, you'll have to make the two
processes cooperate in some way, or worst case, just make sure you
shut one down before you start the other up.

ChrisA


More information about the Python-list mailing list