Source

pypy / dotviewer / graphserver.py

The branch 'kill-more-multimethods' does not exist.
Diff from to

File dotviewer/graphserver.py

 #! /usr/bin/env python
-"""
-Usage:
-    graphserver.py [interface:]port
-    dotviewer.py --server [interface:]port
+"""Graph server.
 
-Start a server listening for connexions on the given port.  The two ways
-to start a server are equivalent.  The server displays the graphs sent
-by a remote process.  On the remote process' side, set the GRAPHSERVER
-environment variable to HOST:PORT.
-
-Here is a step-by-step example on how to use it in combination with ssh
-port forwarding (replace 9999 with a random port number of your choice,
-e.g. between 8000 and 20000):
-
-  - on your local machine, run:
-        graphserver.py localhost:9999
-
-  - connect to a remote machine, allowing the remote side to contact
-    your local dotviewer:
-        ssh -R9999:localhost:9999 machinename
-
-  - set the $GRAPHSERVER env var on the remote machine to point to the
-    redirected port (in bash):
-        export GRAPHSERVER=:9999
-
-  - then any graph-viewing command you execute while $GRAPHSERVER is set
-    will reach your local dotviewer and basically appear to work
-    completely transparently.
-
-  - to automate steps 2 and 3, I've put the following entry in my local
-    .ssh/config:
-                    Host machinename
-                        RemoteForward 9999 127.0.0.1:9999
-
-    and I've added the 'export GRAPHSERVER=:9999' line to my .bashrc on
-    the remote machine.
+From the command-line it's easier to use sshgraphserver.py instead of this.
 """
 
 import sys
         }
 
 
-def listen_server(local_address):
+def listen_server(local_address, s1=None):
     import socket, graphclient, thread
     if isinstance(local_address, str):
         if ':' in local_address:
         else:
             interface, port = '', local_address
         local_address = interface, int(port)
-    s1 = socket.socket()
-    s1.bind(local_address)
+    if s1 is None:
+        s1 = socket.socket()
+        s1.bind(local_address)
     s1.listen(5)
     print 'listening on %r...' % (s1.getsockname(),)
     while True:
         conn, addr = s1.accept()
-        print 'accepted connexion from %r' % (addr,)
+        print 'accepted connection from %r' % (addr,)
         sock_io = msgstruct.SocketIO(conn)
         handler_io = graphclient.spawn_local_handler()
         thread.start_new_thread(copy_all, (sock_io, handler_io))
             traceback.print_exc(file=f)
             # try to add some explanations
             help = (" | if you want to debug on a remote machine, see\n"
-                    " | instructions in dotviewer/graphserver.py\n")
+                    " | instructions in dotviewer/sshgraphserver.py\n")
             try:
                 import pygame
             except ImportError: