Tag Archives: Python

Winpdb with Python3

You need to have python2.7 installed.

  1. cd /usr/lib/python3/dist-packages/
  2. cp /usr/lib/python2.7/dist-packages/rpdb2.py .
  3. Apply patch
    --- /usr/lib/python2.7/dist-packages/rpdb2.py   2010-08-17 22:12:52.000000000 +0300
    +++ rpdb2.py    2014-05-14 10:37:29.559752856 +0300
    @@ -7280,7 +7280,7 @@
             Set rpdb2 to wrap all signal handlers.
             """
             for key, value in list(vars(signal).items()):
    -            if not key.startswith('SIG') or key in ['SIG_IGN', 'SIG_DFL', 'SIGRTMIN', 'SIGRTMAX']:
    +            if not key.startswith('SIG') or key in ['SIG_IGN', 'SIG_DFL', 'SIGRTMIN', 'SIGRTMAX', 'SIG_BLOCK', 'SIG_BLOCK', 'SIG_UNBLOCK', 'SIG_SETMASK']:
                     continue
     
                 handler = signal.getsignal(value)
    

     

  4. Start Winpdb using python2
  5. Start rpdb2 using python3
    python3 /usr/lib/python3/dist-packages/rpdb2.py --debuggee myscript.py
  6. Attach the newly created debugger to Winpdb.

Exporting API reference from Tornado app - Mistakes to avoid

I've developed a small RESTful service with Tornado and I wanted to generated doc for the exposed API. Lucky me, someone already thought about it and created the sphinxcontrib.autohttp.tornado addon for Sphinx.

The next few tips will help getting the work done:

  1. If you're using python-3, you need to use this file tornado.py. The latest release 1.2.1 (as of 30/04/2014) doesn't work with python-3, because
    methods = inspect.getmembers(handler, predicate=inspect.ismethod)  # returns an empty array with python-3

    The predicate needs to be changed to include ismethod or isfunction

  2. In the subclass of the RequestHandler, be sure that the SUPPORTED_METHODS is defined as a tuple
    SUPPORTED_METHODS=('GET')  # WRONG
    SUPPORTED_METHODS=('GET',)  # CORRECT
    
  3. If you add a decorator to your handler methodes, be sure to use functools.wraps or functools.update_wrapper to copy the docstring of the original method to the function returned by the decorator.