diff -r f9e1e4e50b33 -r 76ef5f340007 Utilities/BackgroundClient.py --- a/Utilities/BackgroundClient.py Tue Jun 20 14:45:35 2017 +0200 +++ b/Utilities/BackgroundClient.py Wed Jun 21 19:40:59 2017 +0200 @@ -29,12 +29,17 @@ """ Class implementing the main part of the background client. """ - def __init__(self, host, port): + def __init__(self, host, port, maxProcs): """ Constructor of the BackgroundClient class. @param host ip address the background service is listening + @type str @param port port of the background service + @type int + @param maxProcs maximum number of CPUs (processes) to use + (0 = determined automatically) + @type int """ self.services = {} self.batchServices = {} @@ -42,6 +47,7 @@ self.connection = socket.create_connection((host, port)) ver = b'Python2' if sys.version_info[0] == 2 else b'Python3' self.connection.sendall(ver) + self.__maxProcs = maxProcs def __initClientService(self, fn, path, module): """ @@ -155,7 +161,12 @@ elif fx.startswith("batch_"): callback = self.batchServices.get(fx) if callback: - callback(data, self.__send, fx, self.__cancelled) + try: + callback(data, self.__send, fx, self.__cancelled, + maxProcesses=self.__maxProcs) + except TypeError: + # for backward compatibility + callback(data, self.__send, fx, self.__cancelled) ret = "__DONE__" else: ret = 'Unknown batch service.' @@ -183,12 +194,12 @@ self.connection.close() if __name__ == '__main__': - if len(sys.argv) != 3: - print('Host and port parameters are missing. Abort.') + if len(sys.argv) != 4: + print('Host, port and max. processes parameters are missing. Abort.') sys.exit(1) - host, port = sys.argv[1:] - backgroundClient = BackgroundClient(host, int(port)) + host, port, maxProcs = sys.argv[1:] + backgroundClient = BackgroundClient(host, int(port), int(maxProcs)) # Start the main loop backgroundClient.run()