#! /usr/bin/env python """ start unpickling exec server """ # this part of the program only executes on the server side # import py py.magic.invoke(compile=1) progname = 'readline_exec_server-1.1' # starting the agent server import sys def getlisteningsocket(hostport): from socket import socket, AF_INET, SOCK_STREAM sock = socket(AF_INET, SOCK_STREAM) sock.bind(hostport) sock.listen(5) return sock def execloop(sock): while 1: try: print progname, 'Entering Accept loop' clientsock,address = sock.accept() print progname, 'got new connection from %s %s' % address clientfile = clientsock.makefile('r+b',0) source = clientfile.readline() clientfile.close() g = {'clientsock' : clientsock, 'address' : address} co = py.code.Source(eval(source)).compile() exec co in g except KeyboardInterrupt: sys.exit(1) except: import traceback traceback.print_exc() def startserver(hostport): if isinstance(hostport, str): host, port = hostport.split(':') hostport = (host, int(port)) sock = getlisteningsocket(hostport) try: execloop(sock) finally: sock.close() if __name__ == '__main__': import sys if len(sys.argv)>1: hostport = sys.argv[1] else: hostport = ':8888' startserver(hostport)