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)
"""
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:
import cPickle
except ImportError:
@ -830,7 +830,7 @@ def get_process():
process_lock.release()
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):
proc = subprocess.Popen(cmd, **kwargs)
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
else:
proc = get_process()
obj = cPickle.dumps([cmd, kwargs, cargs], 0)
header = "%d\n" % len(obj)
proc.stdin.write(header.encode())
obj = base64.b64encode(cPickle.dumps([cmd, kwargs, cargs])) #.encode()
proc.stdin.write(obj)
proc.stdin.write('\n'.encode())
proc.stdin.flush()
txt = proc.stdout.readline()
buflen = int(txt.strip())
obj = proc.stdout.read(buflen)
obj = proc.stdout.readline()
process_pool.append(proc)
ret, out, err, ex = cPickle.loads(obj)
ret, out, err, ex = cPickle.loads(base64.b64decode(obj))
if ex:
# TODO
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:
import cPickle
except ImportError:
@ -17,14 +17,11 @@ except ImportError:
import subprocess
while 1:
txt = sys.stdin.readline()
txt = sys.stdin.readline().strip()
if not txt:
# parent process probably ended
break
buflen = int(txt.strip())
obj = sys.stdin.read(buflen)
[cmd, kwargs, cargs] = cPickle.loads(obj.encode())
[cmd, kwargs, cargs] = cPickle.loads(base64.b64decode(txt))
cargs = cargs or {}
ret = 1
@ -45,10 +42,8 @@ while 1:
# it is just text so maybe we do not need to pickle()
tmp = [ret, out, err, ex]
obj = cPickle.dumps(tmp, 0)
header = "%d\n" % len(obj)
sys.stdout.write(header)
sys.stdout.write(obj.decode(sys.stdout.encoding or 'iso8859-1'))
obj = base64.b64encode(cPickle.dumps(tmp))
sys.stdout.write(obj.decode())
sys.stdout.write('\n')
sys.stdout.flush()