improved compatibility with Python2

This commit is contained in:
Paul Müller 2015-11-11 16:11:28 +01:00
parent 82044ef184
commit 96260d04b3
3 changed files with 11 additions and 2 deletions

View file

@ -14,7 +14,6 @@ sys.path.insert(0, dirname(dirname(abspath(__file__))))
import jobmanager
def func(x):
"""Example function with only one argument"""
time.sleep(x[0]/10)

View file

@ -79,6 +79,9 @@ if sys.version_info[0] == 2:
class JMConnectionResetError(JMConnectionError):
pass
class BrokenPipeError(JMConnectionError):
pass
else:
# Python 3
import queue

View file

@ -26,6 +26,12 @@ if sys.version_info[0] == 2:
math.ceil = my_int_ceil
# Magic conversion from 3 to 2
if sys.version_info[0] == 2:
_jm_compatible_bytearray = lambda x: x
else:
_jm_compatible_bytearray = bytearray
class Loop(object):
"""
@ -1209,8 +1215,9 @@ def FloatValue(val=0.):
def UnsignedIntValue(val=0):
return mp.Value('I', val, lock=True)
def StringValue(num_of_bytes):
return mp.Array('c', bytearray(num_of_bytes), lock=True)
return mp.Array('c', _jm_compatible_bytearray(num_of_bytes), lock=True)
def check_process_termination(proc, identifier, timeout, verbose=0, auto_kill_on_last_resort = False):