https://github.com/realkinetic/tornado-shutdown
Utility library to help graceful shutdown of Tornado processes
https://github.com/realkinetic/tornado-shutdown
python shutdown tornado
Last synced: about 1 year ago
JSON representation
Utility library to help graceful shutdown of Tornado processes
- Host: GitHub
- URL: https://github.com/realkinetic/tornado-shutdown
- Owner: RealKinetic
- License: apache-2.0
- Created: 2017-09-17T17:04:53.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-17T17:11:09.000Z (almost 9 years ago)
- Last Synced: 2025-03-21T12:06:10.540Z (over 1 year ago)
- Topics: python, shutdown, tornado
- Language: Python
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tornado-shutdown
Gracefully handling shutdown for server processes can be complicated. This
module attempts simplify things by handling SIGINT and SIGTERM for you. All you
need to do is add callbacks that are run when those signals are fired.
An example::
from tornado import web
from tornado import ioloop
import tornado_shutdown as shutdown
class MainHandler(web.RequestHandler):
def get(self):
self.write("Hello, world")
application = web.Application([
(r"/", MainHandler),
])
if __name__ == '__main__':
shutdown.install_handlers()
server = application.listen(8888)
shutdown.at_shutdown(server.stop)
ioloop.start()
Run the above code and then issue a kill command in a separate terminal. E.g.:
``kill -2 PROCESS_ID`` or ``kill -15 PROCESS_ID``
This module is meant to be used as a singleton. In order to control the
shutdown deadline, ``TORNADO_SHUTDOWN_DEADLINE`` as an environment variable is
respected.
## Testing
Run ``python -m tornado_shutdown``
Will run an http server on 8888. Kill the process with ``kill -2`` or ``kill
-15`` and done. :)