看门狗蟒蛇卡住了

问题描述

我正在尝试使用 python's watchdog 库读取已安装的 NAS 目录。我想检查创建的所有新文件并侦听正在写入该 NAS 的所有 .xml 文件,然后在检测到新文件后将其写入存储帐户。

一个问题是,虽然最初代码似乎运行良好,但有时进程会卡住。它没有返回任何错误,但似乎停止运行

另一方面,我收到如下错误OSError: exception: exception: access violation reading 0x000002328B98FFFC

这里是代码

import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
#from watchdog.observers.polling import PollingObserver
import logging
import os

logging.basicConfig(
    format='%(asctime)s-%(levelname)s- %(message)s',level=logging.INFO)

class Watcher:
    DIRECTORY_TO_WATCH = "PATH"

    def __init__(self):
        self.observer = Observer()

    def run(self):
        event_handler = Handler()
        self.observer.schedule(
            event_handler,self.DIRECTORY_TO_WATCH,recursive=True)
        self.observer.start()
        try:
            while True:
                time.sleep(1)
        except Exception as e:
            logging.error(
                '\n\n-------Failed to upload to BlobStorage: ' + str(e))
            pass
        self.observer.join()

class Handler(FileSystemEventHandler):

    @staticmethod
    def on_any_event(event):
        if event.is_directory:
            return None

        elif event.event_type == 'created':
            file_name = os.path.split(event.src_path)[1]
            if file_name.startswith('log') and file_name.endswith('.xml'):
                # Take any action here when a file is first created.
                logging.info("Received created event - %s." % event.src_path)
                # WRITE INTO STORAGE ACCOUNT


if __name__ == '__main__':
    w = Watcher()
    w.run()

我使用的是 windows 10 和 python 3.6.5

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)