![]() |
Tornado is a powerful and scalable web framework for Python that is known for its non-blocking network I/O, making it an excellent choice for building web applications and APIs. When it comes to stopping the Tornado web server, it’s essential to do it gracefully to ensure that ongoing connections are handled properly. In this article, we’ll explore methods of demonstrating how to stop the Tornado web server. Proper way to stop a TornadoBelow are the two ways to stop the Tornado web server in Python.
Stop Tornado Web Server Using Keyboard InterruptIn this example, the below code sets up a basic Tornado web server responding with “Hello, Tornado!” at the root path. It defines a handler and an application, then starts the server on port 8889. The server runs until manually interrupted (e.g., by pressing `Ctrl+C`), at which point it prints a shutdown message and gracefully stops the Tornado event loop. Python3
Output: Tornado web server started at http://localhost:8889 When we press ctrl+c it’s stop the server. Stop Tornado Web Server Using Sleep TimerIn this example, below code creates a Tornado web server with a “Hello, Tornado!” response at the root path (“/”). The server listens on port 8889 and automatically stops after 5 seconds, thanks to the scheduled execution of the `stop_server` function using Tornado’s `IOLoop`. The `stop_server` function prints a shutdown message and stops the event loop, ensuring a graceful server shutdown. Python3
Output : Tornado web server started at http://localhost:8889 After 5 sec. Tornado server automatically stopped. |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |