5

I'm using waitress to serve my Django app. I need it to serve the app on two ports simultaneously, in the same thread. (Can't be on a separate process because I need to be able to run it in my debugger in development.)

How can I do that?

Ram Rachum
  • 84,019
  • 84
  • 236
  • 374

2 Answers2

2

The latest version of waitress is now able to listen on multiple sockets, including IPv4 and IPv6.

Instead of passing in a host/port combination you now provide waitress with a space delineated list, and it will create as many sockets as required.

from waitress import serve
serve(wsgiapp, listen='0.0.0.0:8080 [::]:9090 *:6543')
wp78de
  • 18,207
  • 7
  • 43
  • 71
0

I've never used waitress, but the latest documentation doesn't seem to mention using multiple ports. A quick clone and ack for 'port' and 'socket' through the code helped me find runner.py with documented command-line options, and the option --port=PORT doesn't seem to support multiple ports. That's not proof, but a good indication without digging too deep.

If I were to take a stab at adding this feature to waitress, then it sounds like select is what's needed.

Here's a StackOverflow example that uses select to bind a basic server to multiple ports.

Community
  • 1
  • 1
CivFan
  • 13,560
  • 9
  • 41
  • 58