pulsar & pudb/ipdb

146 views
Skip to first unread message

Дмитрий Власов

unread,
Jul 1, 2016, 6:56:53 AM7/1/16
to python-pulsar

Hello!

I'm trying to use python debugger in pulsar handler, but get this error.
Can I use debugger in pulsar? May be I doing something wrong?

Thanks.


(env) scailer@pm pulsartest $ python3 app.py                  
15:19:16 [p=16422, t=139853246056192, INFO, pulsar.arbiter] mailbox serving on 127.0.0.1:35055
15:19:16 [p=16422, t=139853246056192, INFO, pulsar.arbiter] started
15:19:16 [p=16422, t=139853246056192, INFO, pulsar.pulsards] pulsards serving on 127.0.0.1:6410
15:19:16 [p=16422, t=139853246056192, INFO, pulsar.pulsards] started
15:19:16 [p=16422, t=139853246056192, INFO, pulsar.wsgi] started
15:19:16 [p=16428, t=139853246056192, INFO, pulsar.wsgi.worker] wsgi serving on 127.0.0.1:8060
15:19:16 [p=16428, t=139853246056192, INFO, pulsar.wsgi.worker] started
/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/__init__.py:192: UserWarning: A non-default handler for signal 2 is already installed (<function _sighandler_noop at 0x7f3218c929d8>). Skipping pudb interrupt support.
  % (interrupt_signal, old_handler))
15:19:24 [p=16428, t=139853246056192, CRITICAL, pulsar.wsgi] ord() expected a character, but string of length 0 found - @ GET "/".

SERVER_PORT=8060
QUERY_STRING=
SERVER_SOFTWARE=pulsar/1.3.2
HTTP_HOST=127.0.0.1:8060
HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.91 YaBrowser/16.4.0.6115 (beta) Safari/537.36
wsgi.multithread=False
HTTP_ACCEPT_ENCODING=gzip, deflate, sdch
SERVER_NAME=localhost.localdomain
PATH_INFO=/
HTTP_ACCEPT_LANGUAGE=ru,en;q=0.8
wsgi.multiprocess=True
HTTP_UPGRADE_INSECURE_REQUESTS=1
HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
REMOTE_ADDR=127.0.0.1
wsgi.url_scheme=http
SCRIPT_NAME=
wsgi.run_once=False
pulsar.connection=127.0.0.1:46574 session 1
wsgi.file_wrapper=<class 'pulsar.apps.wsgi.wrappers.FileWrapper'>
RAW_URI=/
pulsar.cfg=<pulsar.utils.config.Config object at 0x7f3217254470>
CONTENT_TYPE=
wsgi.version=(1, 0)
wsgi.input=<pulsar.apps.wsgi.formdata.HttpBodyReader object at 0x7f321910f828>
REQUEST_METHOD=GET
REMOTE_PORT=46574
HTTP_CONNECTION=keep-alive
pulsar.cache={'cfg': <pulsar.utils.config.Config object at 0x7f3217254470>, 'response': WsgiResponse(500 Internal Server Error), 'app_handler': /, 'content_types': ContentAccept([('text/html', 1), ('application/xhtml+xml', 1), ('image/webp', 1), ('application/xml', 0.9), ('*/*', 0.8)]), 'mixins': {}, 'handle_wsgi_error': True, 'urlargs': {}}
wsgi.errors=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>
SERVER_PROTOCOL=HTTP/1.1
Traceback (most recent call last):
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pulsar/apps/wsgi/handlers.py", line 150, in _async_call
    response = await response
  File "app.py", line 73, in page
    redis_client = self.redis.client()
  File "app.py", line 73, in page
    redis_client = self.redis.client()
  File "/usr/lib64/python3.5/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/debugger.py", line 173, in dispatch_line
    self.user_line(frame)
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/debugger.py", line 371, in user_line
    self.interaction(frame)
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/debugger.py", line 339, in interaction
    show_exc_dialog=show_exc_dialog)
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/debugger.py", line 2079, in call_with_ui
    return f(*args, **kwargs)
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/debugger.py", line 2296, in interaction
    self.event_loop()
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/debugger.py", line 2240, in event_loop
    % VERSION)
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/debugger.py", line 1917, in message
    [("OK", True)], title=title, **kwargs)
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/debugger.py", line 2079, in call_with_ui
    return f(*args, **kwargs)
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/debugger.py", line 1998, in dialog
    return self.event_loop(w)[0]
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/pudb/debugger.py", line 2256, in event_loop
    keys = self.screen.get_input()
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/urwid/raw_display.py", line 325, in get_input
    keys, raw = self.parse_input(None, None, self.get_available_raw_input())
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/urwid/raw_display.py", line 427, in get_available_raw_input
    codes = self._get_gpm_codes() + self._get_keyboard_codes()
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/urwid/raw_display.py", line 501, in _get_keyboard_codes
    code = self._getch_nodelay()
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/urwid/raw_display.py", line 635, in _getch_nodelay
    return self._getch(0)
  File "/home/scailer/projects/local/pulsartest/env/lib/python3.5/site-packages/urwid/raw_display.py", line 545, in _getch
    return ord(os.read(self._term_input_file.fileno(), 1))
TypeError: ord() expected a character, but string of length 0 found
15:19:24 [p=16428, t=139853246056192, INFO, pulsar.wsgi.worker] GET / HTTP/1.1 - 500 Internal Server Error



...


class WebChat(wsgi.LazyWsgi):
    def __init__(self, server_name):
        self.name = server_name

    def setup(self, environ):
        self.cfg = environ['pulsar.cfg']
        loop = environ['pulsar.connection']._loop
        self.redis = create_store(REDIS_DSN, loop=loop)
        self.ss = create_store(SIGNAL_DSN, loop=loop)
        self.pg = create_store(PG_DSN, loop=loop, pool_size=10, timeout=60.0)
        return wsgi.WsgiHandler([wsgi.Router('/', get=self.page)])

    async def page(self, request):
        from pudb import set_trace; set_trace()  # < problem
        redis_client = self.redis.client()
        val = await redis_client.get(request.url_data.get("key"))
        print ('VALUE FROM REDIS:', val)

        val2 = await self.pg.execute('SELECT * FROM activity')
        print ('VALUE FROM PG (SIMPLE):', len(val2))

        async with self.pg.connect() as conn:
            async with conn.cursor() as cur:
                await cur.execute('SELECT * FROM activity')
                val3 = await cur.fetchall()
        print ('VALUE FROM PG (EXTENDED):', len(val2))

        data = 'OK'
        request.response.content_type = 'text/html'
        request.response.content = to_string(data % request.environ)
        return request.response


def server(callable=None, name=None, data_store=None, **params):
    name = name or 'wsgi'
    data_store = pulsards_url(data_store)
    return wsgi.WSGIServer(callable=WebChat(name), name=name,
                           data_store=data_store, **params)


if __name__ == '__main__':  # pragma nocover
    server().start()



lsbardel

unread,
Jul 9, 2016, 4:51:11 PM7/9/16
to python-pulsar

I'm trying to use python debugger in pulsar handler, but get this error.
Can I use debugger in pulsar? May be I doing something wrong?

 
Yes you can debug with pulsar, it is a python library.
Try using pycharm or something like that, but don't import ``pudb`` in  the application.
Reply all
Reply to author
Forward
0 new messages