Python3 fixes

This commit is contained in:
Thomas Nagy 2016-02-26 14:25:54 +01:00 committed by Thomas Nagy
parent 023c540b80
commit 75e9735a22
No known key found for this signature in database
GPG Key ID: 67A565EDFDF90E64
2 changed files with 13 additions and 20 deletions

View File

@ -9,7 +9,7 @@ The portability fixes try to provide a consistent behavior of the Waf API
through Python versions 2.5 to 3.X and across different platforms (win32, linux, etc) through Python versions 2.5 to 3.X and across different platforms (win32, linux, etc)
""" """
import os, sys, errno, traceback, inspect, re, shutil, datetime, gc, platform, time import os, sys, errno, traceback, inspect, re, shutil, datetime, gc, platform, time, base64
try: try:
import cPickle import cPickle
except ImportError: except ImportError:
@ -830,7 +830,7 @@ def get_process():
process_lock.release() process_lock.release()
return get_process() return get_process()
def run_process(cmd, kwargs, cargs=None): def run_process(cmd, kwargs, cargs={}):
if os.name == 'java' or not kwargs.get('stdout', None) or not kwargs.get('stderr', None): if os.name == 'java' or not kwargs.get('stdout', None) or not kwargs.get('stderr', None):
proc = subprocess.Popen(cmd, **kwargs) proc = subprocess.Popen(cmd, **kwargs)
if kwargs.get('stdout', None) or kwargs.get('stderr', None): if kwargs.get('stdout', None) or kwargs.get('stderr', None):
@ -842,17 +842,15 @@ def run_process(cmd, kwargs, cargs=None):
return status, out, err return status, out, err
else: else:
proc = get_process() proc = get_process()
obj = cPickle.dumps([cmd, kwargs, cargs], 0) obj = base64.b64encode(cPickle.dumps([cmd, kwargs, cargs])) #.encode()
header = "%d\n" % len(obj)
proc.stdin.write(header.encode())
proc.stdin.write(obj) proc.stdin.write(obj)
proc.stdin.write('\n'.encode())
proc.stdin.flush() proc.stdin.flush()
txt = proc.stdout.readline() obj = proc.stdout.readline()
buflen = int(txt.strip())
obj = proc.stdout.read(buflen)
process_pool.append(proc) process_pool.append(proc)
ret, out, err, ex = cPickle.loads(obj)
ret, out, err, ex = cPickle.loads(base64.b64decode(obj))
if ex: if ex:
# TODO # TODO
raise OSError(ex) raise OSError(ex)

View File

@ -5,7 +5,7 @@
""" """
""" """
import os, threading, sys, signal, time, traceback import os, threading, sys, signal, time, traceback, base64
try: try:
import cPickle import cPickle
except ImportError: except ImportError:
@ -17,14 +17,11 @@ except ImportError:
import subprocess import subprocess
while 1: while 1:
txt = sys.stdin.readline() txt = sys.stdin.readline().strip()
if not txt: if not txt:
# parent process probably ended # parent process probably ended
break break
[cmd, kwargs, cargs] = cPickle.loads(base64.b64decode(txt))
buflen = int(txt.strip())
obj = sys.stdin.read(buflen)
[cmd, kwargs, cargs] = cPickle.loads(obj.encode())
cargs = cargs or {} cargs = cargs or {}
ret = 1 ret = 1
@ -45,10 +42,8 @@ while 1:
# it is just text so maybe we do not need to pickle() # it is just text so maybe we do not need to pickle()
tmp = [ret, out, err, ex] tmp = [ret, out, err, ex]
obj = cPickle.dumps(tmp, 0) obj = base64.b64encode(cPickle.dumps(tmp))
sys.stdout.write(obj.decode())
header = "%d\n" % len(obj) sys.stdout.write('\n')
sys.stdout.write(header)
sys.stdout.write(obj.decode(sys.stdout.encoding or 'iso8859-1'))
sys.stdout.flush() sys.stdout.flush()