Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.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停止和启动目录观察程序_Python_Python 3.x_Watchdog_Fileobserver - Fatal编程技术网

Python停止和启动目录观察程序

Python停止和启动目录观察程序,python,python-3.x,watchdog,fileobserver,Python,Python 3.x,Watchdog,Fileobserver,我有一个GUI和一个切换观察者的按钮 def start(self): self.observer.schedule(event_handler=update, path=self.path, recursive=False) self.observer.start() def stop(self): self.observer.unschedule_all() self.observer.stop() self.observer.join() 但是当

我有一个GUI和一个切换观察者的按钮

def start(self):
    self.observer.schedule(event_handler=update, path=self.path, recursive=False)
    self.observer.start()

def stop(self):
    self.observer.unschedule_all()
    self.observer.stop()
    self.observer.join()

但是当我再次运行start方法时,我得到了一个RunTimeError:线程只能启动一次

您可能会得到这个错误,因为您尝试多次启动线程,而线程不能多次启动。我将start调用放入构造函数中,它就起作用了。虽然停止功能与启动功能相反