lmacken / pyrasite

Inject code into running Python processes
http://pyrasite.com
GNU General Public License v3.0
2.8k stars 219 forks source link

Add the ability to control the IPC timeout. #61

Closed TheJakeSchmidt closed 7 years ago

TheJakeSchmidt commented 8 years ago

With a hardcoded 5-second timeout, it's impossible to run commands with pyrasite-shell that take more than 5 seconds. I was bitten by this recently when trying to get heap dumps from a large process, but it can be reproduced easily with time.sleep:

$ pyrasite-shell 11166
Pyrasite Shell 2.0
Connected to 'python'
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(DistantInteractiveConsole)

>>> import time
>>> time.sleep(10)

Traceback (most recent call last):
  File "/home/jakeschmidt/pyrasite/env/bin/pyrasite-shell", line 9, in <module>
    load_entry_point('pyrasite==2.0', 'console_scripts', 'pyrasite-shell')()
  File "/home/jakeschmidt/pyrasite/env/local/lib/python2.7/site-packages/pyrasite-2.0-py2.7.egg/pyrasite/tools/shell.py", line 70, in shell
    payload = ipc.recv()
  File "/home/jakeschmidt/pyrasite/env/local/lib/python2.7/site-packages/pyrasite-2.0-py2.7.egg/pyrasite/ipc.py", line 190, in recv
    header_data = self.recv_bytes(4)
  File "/home/jakeschmidt/pyrasite/env/local/lib/python2.7/site-packages/pyrasite-2.0-py2.7.egg/pyrasite/ipc.py", line 203, in recv_bytes
    chunk = self.sock.recv(n - len(data))
socket.timeout: timed out
nikunjy commented 7 years ago

Is this going to get merged at some point ? This tool would be really useless without this option.

TheJakeSchmidt commented 7 years ago

Friendly ping - @lmacken, any thoughts on this pull request? The test failure is a Travis-CI problem; the tests all pass locally. Issue #55 (posted in August) also requests this feature, so it seems like a lot of users want this.

lmacken commented 7 years ago

Sorry for the delay, this PR looks good to me. Thanks!