summaryrefslogtreecommitdiff
path: root/plac/doc
diff options
context:
space:
mode:
Diffstat (limited to 'plac/doc')
-rw-r--r--plac/doc/test_runp.py26
-rw-r--r--plac/doc/test_server.py18
2 files changed, 37 insertions, 7 deletions
diff --git a/plac/doc/test_runp.py b/plac/doc/test_runp.py
new file mode 100644
index 0000000..65980f8
--- /dev/null
+++ b/plac/doc/test_runp.py
@@ -0,0 +1,26 @@
+"""
+This test should work on Linux if you have both Tkinter installed.
+"""
+
+from __future__ import with_statement
+import plac, plac_tk, time
+
+def gen(n):
+ for i in range(n):
+ yield str(i)
+ time.sleep(.1)
+
+def test():
+ tasks = plac.runp([gen(3), gen(5), gen(10)])
+ for t in tasks:
+ t.result
+
+def test_tkmonitor():
+ mon = plac_tk.TkMonitor('tkmon')
+ i = plac.Interpreter.from_gen([gen(3), gen(5), gen(10)], 'p', [mon])
+ with i:
+ for t in i.tasks():
+ t.run()
+ for t in i.tasks():
+ t.result
+ i.man.stop()
diff --git a/plac/doc/test_server.py b/plac/doc/test_server.py
index a9904ee..81214ee 100644
--- a/plac/doc/test_server.py
+++ b/plac/doc/test_server.py
@@ -14,22 +14,26 @@ wrong command
showall
''']
-def client_send(commands, port):
+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)
- for cmd in commands.splitlines():
- po.stdin.write(cmd + '\n')
- time.sleep(.1) # wait a bit for the server to answer
+ try:
+ for cmd in commands.splitlines():
+ po.stdin.write(cmd + '\n')
+ time.sleep(.1) # wait a bit for the server to answer
+ finally:
+ po.stdin.close()
def test():
port = random.choice(range(2000, 20000))
clients = []
for cmds in COMMANDS:
- cl = multiprocessing.Process(target=client_send, args=(cmds, port))
+ cl = multiprocessing.Process(target=telnet, args=(cmds, port))
clients.append(cl)
cl.start()
- i.stop_server(wait=1)
- i.start_server(port, timeout=.1)
+
+ i.start_server(port, timeout=.5)
for cl in clients:
cl.join()
+ i.stop_server()