Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python3:进程的子类,在run()中调用方法_Python 3.x_Windows_Multiprocessing_Command Pattern - Fatal编程技术网

Python 3.x Python3:进程的子类,在run()中调用方法

Python 3.x Python3:进程的子类,在run()中调用方法,python-3.x,windows,multiprocessing,command-pattern,Python 3.x,Windows,Multiprocessing,Command Pattern,我试图扩展多处理.Process类,以命令模式的方式使用它。。。有一个调度程序实例,客户端在其中调用命令并调用执行。但是调用self.execute()后,命令代码永远不会终止。以下是命令类: class Command(Process): def __init__(self): super().__init__() self.result = None self.command_name = type(self).__name__

我试图扩展
多处理.Process
类,以命令模式的方式使用它。。。有一个调度程序实例,客户端在其中调用命令并调用执行。但是调用
self.execute()
后,命令代码永远不会终止。以下是命令类:

   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("Waiting\n")              
            command.join(10)
            if command.is_alive():
                print("process isn't finished")
            else:
                print("process finished")               
        self._history_queue.append(command)
我尝试在运行成功(进程终止)后立即调用sys.exit(0)。因此,继承层次结构中可能存在错误,但我看不到它