diff options
author | Michele Simionato <michele.simionato@gmail.com> | 2011-06-05 11:56:50 +0200 |
---|---|---|
committer | Michele Simionato <michele.simionato@gmail.com> | 2011-06-05 11:56:50 +0200 |
commit | 2c9a92feab665152a02a7482bff9d31bafa2996e (patch) | |
tree | 45cd87cf2a0ba28882cdc552722bb0ee2001a6af | |
parent | 10e47a954cf45360667d4d581314663ee5626a13 (diff) | |
download | micheles-2c9a92feab665152a02a7482bff9d31bafa2996e.tar.gz |
Fixed a test with the server
-rw-r--r-- | plac/doc/example1.py | 1 | ||||
-rw-r--r-- | plac/doc/test_runp.py | 2 | ||||
-rw-r--r-- | plac/doc/test_server.py | 9 | ||||
-rw-r--r-- | 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) |