[Web-SIG] WSGI server/adapter and sys.exit()/SystemExit exception.

Robert Brewer fumanchu at amor.org
Thu Mar 8 00:25:07 CET 2007

Graham Dumpleton wrote:
> The question is, if a WSGI application calls sys.exit() or raises a
> SystemExit exception explicitly, what action if any should a WSGI
> server/adapter take in response. Should it allow the process to be
> shutdown, or should it ignore it.
> ...to my mind any WSGI server/adapter should possibly always ignore
> a SystemExit exception coming from with an executing WSGI application.
> One though also has to worry about SystemExit exceptions raised as a
> side effect of a Python import performed to load a WSGI application.
> Then you potentially have the issue of SystemExit exception raised
> from thread spawned by WSGI application.

For now, I'd try to give deployers using my tools direct control over
whether an application is allowed to stop the process or not via

In a future pywebd/webctl world, I'd like to see process
shutdown/restart delegated to plugins only, which can then be
attached/detached by deployers. For example, the current pywebd
autoreload plugin can call os.execv; if you're deploying with mod_python
that autoreload plugin is simply never attached and therefore cannot
call execv. If deploying by calling a hypothetical 'webctl' script, I
would expect a command-line arg or config entry which controlled whether
or not to plug in the autoreloader. Finally, when deploying from
CherryPy itself, it plugs in (and configures) the autoreloader based on
the existing CherryPy config semantics.

Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org

More information about the Web-SIG mailing list