Z
Z
zaart2021-04-23 00:51:37
linux
zaart, 2021-04-23 00:51:37

How to properly terminate a tornado process (python)?

Hello!

I wrote a server script in python using the Tornado framework. But I ran into a problem when I complete the script, the process itself does not end and remains hanging in the background. Because of this, the port is not released and I cannot run the script again. Tell me, please, what to do?

6081ef1bcabea323622814.png

Web server code

# Класс, реализующий веб-сервер
class WebServer(tornado.web.Application):

    def init(self):
        self.fd = FaceDetector()

        # Прописываем роутинг
        handlers = [
            (r"/FindFaces", FindFacesHandler),
            (r"/PredictFaceShape", PredictFaceShapeHandler),
            (r"/CompareFaces", CompareFacesHandler),
        ]
        # Настройки веб-сервера
        settings = dict(
            cookie_secret="TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE",
            debug=True
        )
        # Передаём обработчики запросов и настройки в конструктор базового класса
        super().init(handlers, **settings)

    # Запускает веб-сервер в работу
    def run(self, port: int):
        # Указываем, какой порт будет прослушивать сервер
        self.listen(port, address='127.0.0.1')
        # Запускаем цикл обработки событий
        shutdown_event = tornado.locks.Event()
        tornado.ioloop.IOLoop.current().run_sync(shutdown_event.wait)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question