joerick / pyinstrument

🚴 Call stack profiler for Python. Shows you why your code is slow!
https://pyinstrument.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
6.63k stars 232 forks source link

redis-py while profiling results in ConnectionError #32

Closed sYnfo closed 6 years ago

sYnfo commented 6 years ago

With python 3.6.3, redis 2.10.6 and the pyinstrument currently on pypi, I get a ConnectionError when connecting to redis while the profiler is running. Reproducer:

import redis
from pyinstrument import Profiler

_redis = redis.StrictRedis(...)
_redis.get('foo')
print('Works')

profiler = Profiler()
profiler.start()
_redis = redis.StrictRedis(...)
_redis.get('foo')
print('Fails')

Traceback

Traceback (most recent call last):
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 484, in connect
    sock = self._connect()
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 541, in _connect
    raise err
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 529, in _connect
    sock.connect(socket_address)
OSError: [Errno 22] Invalid argument

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/client.py", line 667, in execute_command
    connection.send_command(*args)
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 610, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 585, in send_packed_command
    self.connect()
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 489, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 22 connecting to 35.195.188.81:6379. Invalid argument.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 484, in connect
    sock = self._connect()
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 541, in _connect
    raise err
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 529, in _connect
    sock.connect(socket_address)
OSError: [Errno 22] Invalid argument

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 22, in <module>
    _redis.get('foo')
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/client.py", line 976, in get
    return self.execute_command('GET', name)
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/client.py", line 673, in execute_command
    connection.send_command(*args)
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 610, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 585, in send_packed_command
    self.connect()
  File "/Users/matt/us-research/env/lib/python3.6/site-packages/redis/connection.py", line 489, in connect
joerick commented 6 years ago

I wonder if this is due to the system signals in pyinstrument 0.x... could you try again with pip install pyinstrument==2.0.0b1?

sYnfo commented 6 years ago

That actually works, feel free to close I guess :)

joerick commented 6 years ago

Great. Thanks for getting back. The next version should be released in the next week or so!

Pyinstrument refactored to use a new profiling mode. Rather than using signals, pyintrument uses a new statistical profiler built on PyEval_SetProfile. This means no more main thread restriction, no more IO errors when using Pyinstrument, and no more 'setprofile' mode!