本文整理汇总了Python中watchdog.events.RegexMatchingEventHandler方法的典型用法代码示例。如果您正苦于以下问题:Python events.RegexMatchingEventHandler方法的具体用法?Python events.RegexMatchingEventHandler怎么用?Python events.RegexMatchingEventHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类watchdog.events
的用法示例。
在下文中一共展示了events.RegexMatchingEventHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from watchdog import events [as 别名]
# 或者: from watchdog.events import RegexMatchingEventHandler [as 别名]
def main(directory):
cjwstate.modules.init_module_system()
path = pathlib.Path(directory)
def reload():
if os.path.isdir(path / "locale"):
try:
logger.info(f"Extracting i18n messages...")
extract_module_messages(path)
except Exception:
logger.exception("Error extracting module translations")
return
try:
logger.info(f"Importing module...")
import_module_from_directory(path)
except Exception:
logger.exception("Error loading module")
want_reload = False
class ReloadEventHandler(RegexMatchingEventHandler):
def on_any_event(self, ev):
nonlocal want_reload
want_reload = True
regexes = [".*\\.(py|json|yaml|html|po|pot)"]
event_handler = ReloadEventHandler(regexes=regexes)
observer = Observer()
observer.schedule(event_handler, directory, recursive=True)
observer.start()
reload()
try:
while True:
time.sleep(0.05) # 50ms
# Call `reload()` if Watchdog has notified us in the past 50ms.
if want_reload:
reload()
want_reload = False
except KeyboardInterrupt:
observer.stop()
observer.join()