Permalink
Browse files

support connecting to rpyc through unix domain sockets

  • Loading branch information...
1 parent 2ea61b1 commit 760b3d821b21a6ef04b5aeaf0a26e38ad156b313 @alonho committed Nov 27, 2012
Showing with 22 additions and 20 deletions.
  1. +9 −7 pystuck/__init__.py
  2. +11 −11 pystuck/rpyc_tools.py
  3. +2 −2 setup.py
View
@@ -1,5 +1,6 @@
import socket
-from pystuck.rpyc_tools import run_server, connect, DEFAULT_HOST, DEFAULT_PORT
+from rpyc.utils.classic import connect, unix_connect
+from pystuck.rpyc_tools import run_server, DEFAULT_HOST, DEFAULT_PORT
README = """
pystuck.py is a utility for analyzing stuck python programs (or just hardcore debugging).
@@ -12,8 +13,8 @@
in addition, it opens an ipython prompt with an rpyc connection that provides
access to the debuggee's modules (good for inspecting variables)."""
-def run_client(host=DEFAULT_HOST, port=DEFAULT_PORT, stacks=True, ipython=True, greenlets=True):
- conn = connect(host=host, port=port)
+def run_client(host=DEFAULT_HOST, port=DEFAULT_PORT, unix_socket=None, stacks=True, ipython=True, greenlets=True):
+ conn = connect(host=host, port=port) if unix_socket is None else unix_connect(unix_socket)
if stacks:
print conn.modules['pystuck.thread_probe'].stacks_repr(greenlets=greenlets)
if ipython:
@@ -26,10 +27,11 @@ def main():
import argparse
parser = argparse.ArgumentParser(description=README)
- parser.add_argument('host', nargs='?', default=DEFAULT_HOST, help='server address (default: {})'.format(DEFAULT_HOST))
- parser.add_argument('port', nargs='?', default=DEFAULT_PORT, help='server port (default: {})'.format(DEFAULT_PORT))
- parser.add_argument('--no-stacks', action='store_false', dest='stacks', help="don't print the debugee's threads and stacks")
- parser.add_argument('--exclude-greenlets', action='store_false', dest='greenlets', help="don't print the debugee's greenlets stacks")
+ parser.add_argument('--host', default=DEFAULT_HOST, help='server address (default: {})'.format(DEFAULT_HOST))
+ parser.add_argument('--port', default=DEFAULT_PORT, help='server port (default: {})'.format(DEFAULT_PORT))
+ parser.add_argument('--unix_socket', default=None, help='server unix domain socket')
+ parser.add_argument('--no-stacks', action='store_false', dest='stacks', help="don't print the debugee's threads/greenlets")
+ parser.add_argument('--exclude-greenlets', action='store_false', dest='greenlets', help="don't print the debugee's greenlets. pass it when the process hogs memory as printing greenlets requires traversal of all objects in the garbage collector")
parser.add_argument('--no-ipython', action='store_false', dest='ipython', help="don't open an ipython prompt for debugging")
args = parser.parse_args()
View
@@ -1,21 +1,21 @@
-from rpyc.utils.classic import connect as rpyc_connect
from rpyc.utils.server import ThreadedServer
from rpyc.core import SlaveService
import threading
+import os
DEFAULT_PORT = 6666
-#DEFAULT_PORT = os.getpid() # multiple processes can co-exist
-DEFAULT_HOST = "127.0.0.1"
-#DEFAULT_HOST = "0.0.0.0" # reachable from outside the machine (security hole!)
+DEFAULT_HOST = "127.0.0.1"
-def run_server(host=DEFAULT_HOST, port=DEFAULT_PORT):
+def run_server(host=DEFAULT_HOST, port=DEFAULT_PORT, unix_socket=None):
+ args = dict(hostname=host, port=port) if unix_socket is None else dict(socket_path=unix_socket)
+ if unix_socket is not None:
+ try:
+ os.unlink(unix_socket)
+ except OSError:
+ pass
server = ThreadedServer(service=SlaveService,
- hostname=host,
- port=port,
- auto_register=False)
+ auto_register=False,
+ **args)
thread = threading.Thread(target=server.start)
thread.daemon = True
thread.start()
-
-def connect(host=DEFAULT_HOST, port=DEFAULT_PORT):
- return rpyc_connect(host=host, port=port)
View
@@ -12,14 +12,14 @@
access to the debuggee's modules (good for inspecting variables)."""
setup(name='pystuck',
- version='0.3',
+ version='0.4',
classifiers = ["Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 2.7"],
description=README,
author='Alon Horev',
- author_email='alon@horev.net',
+ author_email='alonho@gmail.com',
packages=['pystuck'],
install_requires=['rpyc>=3', 'ipython'],
license='BSD',

0 comments on commit 760b3d8

Please sign in to comment.