#3576 patch from michikarg for genpy.py py3k compat
This commit is contained in:
parent
a0269e043e
commit
8dbd617c07
|
@ -884,8 +884,8 @@ def serialize_fn_generator(package, spec, is_numpy=False):
|
|||
for y in serializer_generator(package, flatten(spec), True, is_numpy):
|
||||
yield " "+y
|
||||
pop_context()
|
||||
yield "except struct.error, se: self._check_types(se)"
|
||||
yield "except TypeError, te: self._check_types(te)"
|
||||
yield "except struct.error as se: self._check_types(se)"
|
||||
yield "except TypeError as te: self._check_types(te)"
|
||||
# done w/ method-var context #
|
||||
|
||||
def deserialize_fn_generator(package, spec, is_numpy=False):
|
||||
|
@ -919,7 +919,7 @@ def deserialize_fn_generator(package, spec, is_numpy=False):
|
|||
yield " %s"%code
|
||||
|
||||
yield " return self"
|
||||
yield "except struct.error, e:"
|
||||
yield "except struct.error as e:"
|
||||
yield " raise roslib.message.DeserializationError(e) #most likely buffer underfill"
|
||||
|
||||
def msg_generator(package, name, spec):
|
||||
|
@ -943,7 +943,7 @@ def msg_generator(package, name, spec):
|
|||
# for older versions of msg files
|
||||
try:
|
||||
gendeps_dict = roslib.gentools.get_dependencies(spec, package, compute_files=False)
|
||||
except roslib.msgs.MsgSpecException, e:
|
||||
except roslib.msgs.MsgSpecException as e:
|
||||
raise MsgGenerationException("Cannot generate .msg for %s/%s: %s"%(package, name, str(e)))
|
||||
md5sum = roslib.gentools.compute_md5(gendeps_dict)
|
||||
|
||||
|
|
|
@ -40,6 +40,19 @@ import roslib
|
|||
import roslib.rospack
|
||||
import threading
|
||||
|
||||
if sys.hexversion > 0x03000000: #Python3
|
||||
python3 = True
|
||||
else:
|
||||
python3 = False
|
||||
|
||||
def _read_stdout(cmd):
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
std_out, std_err = p.communicate()
|
||||
if python3:
|
||||
return std_out.decode()
|
||||
else:
|
||||
return std_out
|
||||
|
||||
def num_cpus():
|
||||
"""
|
||||
Detects the number of CPUs on a system. Cribbed from pp.
|
||||
|
@ -52,7 +65,7 @@ def num_cpus():
|
|||
if isinstance(ncpus, int) and ncpus > 0:
|
||||
return ncpus
|
||||
else: # OSX:
|
||||
return subprocess.call("sysctl -n hw.ncpu".split())
|
||||
return int(_read_stdout(["sysctl", "-n", "hw.ncpu"])) or 1
|
||||
# Windows:
|
||||
if "NUMBER_OF_PROCESSORS" in os.environ:
|
||||
ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
|
||||
|
|
Loading…
Reference in New Issue