The stdlib offers wsgiref.simple_server [1] which is single-threaded. You gave a flask example but it'll work fine for any wsgi app.
The example on https://trypyramid.com which I'll copy here will work for any wsgi app including flask. from wsgiref.simple_server import make_server from pyramid.config import Configurator from pyramid.response import Response def hello_world(request): return Response('Hello World!') if __name__ == '__main__': with Configurator() as config: config.add_route('hello', '/') config.add_view(hello_world, route_name='hello') app = config.make_wsgi_app() server = make_server('0.0.0.0', 6543, app) server.serve_forever() Pyramid also exposes a wsgiref entry point if you are using PasteDeploy such that you can use it from your INI file like: [server:main] use = egg:pyramid#wsgiref host = 0.0.0.0 port = 8080 [1] https://docs.python.org/3/library/wsgiref.html#module-wsgiref.simple_server > On May 22, 2025, at 16:27, Jonathan Vanasco <[email protected]> wrote: > > I can't speak to your Waitress questions, but uwsgi will build on windows > with cygwin and can run multiple processes with single threads. > > > On Thursday, May 22, 2025 at 4:48:06 PM UTC-4 Tom Hendrikx wrote: >> Hi, >> >> For a work project I'm building Python software that runs inside a rather >> limited environment. An upstream software supplier provides software that >> spawns a Python environment where I need to execute code that is not >> thread-safe. The upstream supplier did add some mechanics to allow thread >> safety, but it requires me to call some custom code from each newly spawned >> thread. >> >> The actual functionality that I need to run in the environment is a small >> Flask app. When running this app using the Flask builtin dev server, it only >> works when I disable threads using: flask_app.run(threaded=False). >> >> Now I wanted to not use the Flask dev server but something a little more >> sophisticated. Enter waitress: it runs on Windows (hard requirement), it's >> simple and it can serve my Flask app directly from Python (no external >> servers like apache+mod_wsgi required). There is only a single client >> sending requests to the server, so performance/concurrency is not a >> requirement. >> >> However, I cannot get waitress to run as a single thread. Settings threads=1 >> doesn't help (it's probably the master process + 1 task thread). I found a >> SO post [1] that suggests two options, but both don't work: setting the >> parameter "threaded" to False, but this parameter doesn't exist (in waitress >> 3.0.2), and setting "connection_limit" to 1, which renders the app >> unreachable. >> >> Running threaded would probably mean that I subclass the >> ThreadedTaskDispatcher to add the specific code from the supplier. Another >> option would be to create a non-threading Dispatcher myself from scratch, >> and use that. All that seems way too complicated. >> >> Do you have advice for me? Can I even run waitress without threads? Where >> did the "threaded" parameter to the serve() function go, if it ever existed? >> Should I be looking at a different Python-only app server that I somehow >> didn't find in my searches, and works on Windows? Should I even bother and >> just use the Flask dev server? >> >> [1] https://stackoverflow.com/a/78515009/2991260 >> >> Thanks for all knowledge you might be able to share >> >> Kind regards, >> Tom > > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To view this discussion visit > https://groups.google.com/d/msgid/pylons-discuss/f1d3abc3-0f31-41b7-84dc-0febcf191228n%40googlegroups.com > > <https://groups.google.com/d/msgid/pylons-discuss/f1d3abc3-0f31-41b7-84dc-0febcf191228n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/pylons-discuss/0692761A-88C5-4D24-BE3A-A7F2942349DB%40gmail.com.
