From f10accf861fa3e8ef54c1b6e96cc7440a6e18c27 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Mon, 19 Jan 2015 22:35:20 +0100 Subject: [PATCH] cleanup --- playground/prefork/preforkjava.py | 26 ++++++++++++++++++-------- waflib/extras/prefork.py | 22 ++++++++++++++++------ waflib/extras/preforkunix.py | 27 ++++++++++++++++----------- 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/playground/prefork/preforkjava.py b/playground/prefork/preforkjava.py index b4d35320..e9d2dfed 100755 --- a/playground/prefork/preforkjava.py +++ b/playground/prefork/preforkjava.py @@ -56,10 +56,11 @@ if 1: PORT = 51200 def make_server(bld, idx): - wd = os.path.dirname(os.path.abspath('__file__')) + #wd = os.path.dirname(os.path.abspath('__file__')) + wd = "/home/tnagy/" port = PORT + idx cmd = "java -cp %s/minimal-json-0.9.3-SNAPSHOT.jar:. Prefork %d" % (wd, PORT) - proc = subprocess.Popen(cmd.split(), shell=False, cwd=d) + proc = subprocess.Popen(cmd.split(), shell=False, cwd=wd) proc.port = port return proc @@ -84,17 +85,26 @@ if 1: atexit.register(close_all) def put_data(conn, data): - conn.send(data) + cnt = 0 + while cnt < len(data): + sent = conn.send(data[cnt:]) + if sent == 0: + raise RuntimeError('connection ended') + cnt += sent def read_data(conn, siz): - ret = conn.recv(siz) - #if not ret: - # print("closed connection?") - assert(len(ret) == siz) + cnt = 0 + buf = [] + while cnt < siz: + data = conn.recv(min(siz - cnt, 1024)) + if not data: + raise RuntimeError('connection ended %r %r' % (cnt, siz)) + buf.append(data) + cnt += len(data) + ret = ''.join(buf) return ret def exec_command(self, cmd, **kw): - if 'stdout' in kw: if kw['stdout'] not in (None, subprocess.PIPE): return self.exec_command_old(cmd, **kw) diff --git a/waflib/extras/prefork.py b/waflib/extras/prefork.py index a1583c4e..79e4e5a2 100755 --- a/waflib/extras/prefork.py +++ b/waflib/extras/prefork.py @@ -87,6 +87,7 @@ class req(SocketServer.StreamRequestHandler): self.wfile.write(make_header(params)) if data: self.wfile.write(data) + self.wfile.flush() def process_command(self): query = self.rfile.read(HEADER_SIZE) @@ -229,17 +230,26 @@ else: atexit.register(close_all) def put_data(conn, data): - conn.send(data) + cnt = 0 + while cnt < len(data): + sent = conn.send(data[cnt:]) + if sent == 0: + raise RuntimeError('connection ended') + cnt += sent def read_data(conn, siz): - ret = conn.recv(siz) - #if not ret: - # print("closed connection?") - assert(len(ret) == siz) + cnt = 0 + buf = [] + while cnt < siz: + data = conn.recv(min(siz - cnt, 1024)) + if not data: + raise RuntimeError('connection ended %r %r' % (cnt, siz)) + buf.append(data) + cnt += len(data) + ret = ''.join(buf) return ret def exec_command(self, cmd, **kw): - if 'stdout' in kw: if kw['stdout'] not in (None, subprocess.PIPE): return self.exec_command_old(cmd, **kw) diff --git a/waflib/extras/preforkunix.py b/waflib/extras/preforkunix.py index f583dd49..58f48be7 100755 --- a/waflib/extras/preforkunix.py +++ b/waflib/extras/preforkunix.py @@ -19,11 +19,7 @@ To use:: more code """ -import os, re, socket, threading, sys, subprocess, time, atexit, traceback, random -try: - import SocketServer -except ImportError: - import socketserver as SocketServer +import os, re, socket, threading, sys, subprocess, atexit, traceback try: from queue import Queue except ImportError: @@ -173,17 +169,26 @@ if 1: atexit.register(close_all) def put_data(conn, data): - conn.send(data) + cnt = 0 + while cnt < len(data): + sent = conn.send(data[cnt:]) + if sent == 0: + raise RuntimeError('connection ended') + cnt += sent def read_data(conn, siz): - ret = conn.recv(siz) - #if not ret: - # print("closed connection?") - assert(len(ret) == siz) + cnt = 0 + buf = [] + while cnt < siz: + data = conn.recv(min(siz - cnt, 1024)) + if not data: + raise RuntimeError('connection ended %r %r' % (cnt, siz)) + buf.append(data) + cnt += len(data) + ret = ''.join(buf) return ret def exec_command(self, cmd, **kw): - if 'stdout' in kw: if kw['stdout'] not in (None, subprocess.PIPE): return self.exec_command_old(cmd, **kw)