本文整理匯總了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()