From 2c9a92feab665152a02a7482bff9d31bafa2996e Mon Sep 17 00:00:00 2001 From: Michele Simionato Date: Sun, 5 Jun 2011 11:56:50 +0200 Subject: Fixed a test with the server --- plac/doc/example1.py | 1 - plac/doc/test_runp.py | 2 +- plac/doc/test_server.py | 9 ++++----- plac/plac_ext.py | 8 ++------ 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/plac/doc/example1.py b/plac/doc/example1.py index a5071bb..f024090 100644 --- a/plac/doc/example1.py +++ b/plac/doc/example1.py @@ -1,7 +1,6 @@ # example1.py def main(dsn): "Do something with the database" - print(dsn) # ... if __name__ == '__main__': diff --git a/plac/doc/test_runp.py b/plac/doc/test_runp.py index 619fc1f..4cdd494 100644 --- a/plac/doc/test_runp.py +++ b/plac/doc/test_runp.py @@ -1,5 +1,5 @@ """ -This test should work on Linux if you have both Tkinter installed. +This test should work on Linux if you have Tkinter installed. """ from __future__ import with_statement diff --git a/plac/doc/test_server.py b/plac/doc/test_server.py index a46535d..adcc395 100644 --- a/plac/doc/test_server.py +++ b/plac/doc/test_server.py @@ -1,4 +1,4 @@ -import multiprocessing, subprocess, time, random +import multiprocessing, subprocess, random, time import plac from ishelve2 import ShelveInterface @@ -15,7 +15,6 @@ showall '''] def telnet(commands, port): - time.sleep(.5) # wait a bit for the server to start po = subprocess.Popen(['telnet', 'localhost', str(port)], stdin=subprocess.PIPE) try: @@ -27,13 +26,13 @@ def telnet(commands, port): def test(): port = random.choice(range(2000, 20000)) + server = multiprocessing.Process(target=i.start_server, args=(port,)) + server.start() clients = [] for cmds in COMMANDS: cl = multiprocessing.Process(target=telnet, args=(cmds, port)) clients.append(cl) cl.start() - - i.start_server(port, timeout=.5) for cl in clients: cl.join() - i.stop_server() + server.terminate() diff --git a/plac/plac_ext.py b/plac/plac_ext.py index ae665b0..35106ae 100644 --- a/plac/plac_ext.py +++ b/plac/plac_ext.py @@ -721,7 +721,7 @@ class _AsynHandler(asynchat.async_chat): line = ''.join(self.data) self.log('Received line %r from %s' % (line, self.addr)) if line == 'EOF': - self.i.__exit__() + self.i.__exit__(None, None, None) self.handle_close() else: task = self.i.submit(line) @@ -990,15 +990,11 @@ class Interpreter(object): _AsynServer(self, _AsynHandler, port) # register the server try: asyncore.loop(**kw) - except KeyboardInterrupt: + except (KeyboardInterrupt, TerminatedProcess): pass finally: asyncore.close_all() - def stop_server(self, after=0.0): - "Stops the asyncore server, possibly after a given number of seconds" - threading.Timer(after, asyncore.socket_map.clear).start() - def add_monitor(self, mon): self.man.add(mon) -- cgit v1.2.1