From 0917dbecf97843edfc40d779b5a516caac9a85bc Mon Sep 17 00:00:00 2001 From: Dario Mapelli Date: Tue, 8 Jun 2021 15:32:21 +0200 Subject: [PATCH] [py2py3] fix unittests from #10289 - src --- src/python/WMCore/ProcessPool/ProcessPool.py | 24 +++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/python/WMCore/ProcessPool/ProcessPool.py b/src/python/WMCore/ProcessPool/ProcessPool.py index 6cee2971d1c..61d5024d74f 100644 --- a/src/python/WMCore/ProcessPool/ProcessPool.py +++ b/src/python/WMCore/ProcessPool/ProcessPool.py @@ -97,7 +97,7 @@ def __init__(self, slaveClassName, totalSlaves, componentDir, self.slaveClassName = slaveClassName self.componentDir = componentDir self.config = config - self.versionString = "python2" + self.versionString = "python3" if PY3 else "python2" self.workers = [] self.nSlaves = totalSlaves @@ -208,7 +208,10 @@ def close(self): for i in range(self.nSlaves): try: encodedWork = self.jsonHandler.encode('STOP') - self.sender.send(encodedWork) + if PY3: + self.sender.send_string(encodedWork) + else: + self.sender.send(encodedWork) except Exception as ex: # Might be already failed. Nothing you can # really do about that. @@ -400,7 +403,7 @@ def setupDB(config, wmInit): logging.error("Something in the way of the config path") sys.exit(1) - with open(configPath, 'r') as f: + with open(configPath, 'rb') as f: config = pickle.load(f) @@ -443,7 +446,10 @@ def setupDB(config, wmInit): try: output = {'type': 'ERROR', 'msg': crashMessage} encodedOutput = jsonHandler.encode(output) - sender.send(encodedOutput) + if PY3: + sender.send_string(encodedOutput) + else: + sender.send(encodedOutput) logging.error("Sent error message and now breaking") break except Exception as ex: @@ -456,10 +462,16 @@ def setupDB(config, wmInit): if isinstance(output, list): for item in output: encodedOutput = jsonHandler.encode(item) - sender.send(encodedOutput) + if PY3: + sender.send_string(encodedOutput) + else: + sender.send(encodedOutput) else: encodedOutput = jsonHandler.encode(output) - sender.send(encodedOutput) + if PY3: + sender.send_string(encodedOutput) + else: + sender.send(encodedOutput) logging.info("Process with PID %s finished" % (os.getpid())) del jsonHandler