Python3: подкласс процесса, методы вызова в run()

#python-3.x #windows #multiprocessing #command-pattern

#python-3.x #Windows #многопроцессорная обработка #команда-шаблон

Вопрос:

Я попытался расширить multiprocessing.Process класс, чтобы использовать его в виде командного шаблона… Существует экземпляр планировщика, в котором клиент вызывает команды и вызывает выполнение. Но код команды никогда не завершается после self.execute() вызова. Вот класс command:

    class Command(Process):
    def __init__(self):
        super().__init__()
        self.result = None
        self.command_name = type(self).__name__
        self.shell = False      

    #from Process
    def run(self):
        super().run()
        print("running " self.command_name)
        sys.stdout.flush()
        self.execute()
        print("finished " self.command_name)
        sys.stdout.flush()
        sys.exit(0)

    def execute(self):
        pass
  

идея проста, что каждый подкласс команды предоставляет свой собственный код в методе execute() . Для экземпляров:

 class LoadCommand(Command):
 def __init__(self,parameterA,...):
     super().__init__()
     ...

 def execute(self):
     print("executing LoadCommand")
     ....
     return
  

это мой планировщик:

 class Scheduler:
_instance = None
_history_queue = []
_command_queue = []
_logger = None
#IPC, negative maxsize means infinite size
_pipe = Queue(maxsize=-1)

def __init__(self):
    raise RuntimeError('Call getInstance() instead')

@classmethod
def getInstance(cls):
    if cls._instance is None:
        cls._instance = cls.__new__(cls)
    return cls._instance

def getPipe(self):
    print(self._pipe)
    return self._pipe

def enqueueCommand(self,command):
    # if isinstance(command,Command):
        self._command_queue.append(command)

def executeQueue(self, synchronicMode):
    while len(self._command_queue) > 0:
        command = self._command_queue.pop(0)    
        command.start()
        if synchronicMode:
            #wait until this process is done
            print("Waitingn")              
            command.join(10)
            if command.is_alive():
                print("process isn't finished")
            else:
                print("process finished")               
        self._history_queue.append(command)
  

Я попытался вызвать sys.exit(0) сразу после успешного запуска (процесс завершается). Так что, возможно, в иерархии наследования есть ошибка, но я ее не вижу.