Set breakpoints in the Tornado app

How can I set a breakpoint in my tornado app?
I tried pdb, but Tornado application stubs ignored my pdb.set_trace () command in my application.

+3
source share
2 answers

If you use the application using the wizard, you must set the environment variable in the .env file to the root folder of the project. Setting below the env variable in my .env file made a mark with me.

PYTHONUNBUFFERED = true

Now I can set the code breakpoints in my application, and also print the output in the server logs during the application launch using the wizard.

+2

pdb.set_trace()...? :

#!/usr/bin/python
# -*- coding: utf-8 -*-

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import pdb 

from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

class IndexHandler(tornado.web.RequestHandler):
    def get(self):
        greeting = self.get_argument('greeting', 'Hello')
        reself.write(greeting + ', friendly user!')

if __name__ == "__main__":
    tornado.options.parse_command_line()
    app = tornado.web.Application(handlers=[(r"/", IndexHandler)])
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    pdb.set_trace()
    tornado.ioloop.IOLoop.instance().start()

:

$ python test.py
> /home/mariusz/Dokumenty/Projekty/Testy/test.py(24)<module>()
-> tornado.ioloop.IOLoop.instance().start()
(Pdb) break 16
Breakpoint 1 at /home/mariusz/Dokumenty/Projekty/Testy/test.py:16
(Pdb) continue
> /home/mariusz/Dokumenty/Projekty/Testy/test.py(16)get()
-> self.write(greeting + ', friendly user!')
(Pdb) step
--Call--
> /usr/local/lib/python2.7/dist-packages/tornado/web.py(497)write()
-> def write(self, chunk):
(Pdb) step
> /usr/local/lib/python2.7/dist-packages/tornado/web.py(512)write()
-> if self._finished:
(Pdb) step
> /usr/local/lib/python2.7/dist-packages/tornado/web.py(516)write()
-> if isinstance(chunk, dict):
(Pdb) 

continue , http://localhost:8000/ , RequestHandler.

+1

Source: https://habr.com/ru/post/1613163/


All Articles