mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Use PollingObserver() only on OS X.
This commit is contained in:
parent
181c2973e6
commit
5b442a8947
@ -1,7 +1,12 @@
|
||||
import os
|
||||
import fnmatch
|
||||
import sys
|
||||
from watchdog.events import PatternMatchingEventHandler
|
||||
from watchdog.observers.polling import PollingObserver
|
||||
if sys.platform == 'darwin':
|
||||
from watchdog.observers.polling import PollingObserver as Observer
|
||||
else:
|
||||
from watchdog.observers import Observer
|
||||
# Use PollingObserver on OS X, and natvie Observer on Linux and Windows
|
||||
|
||||
_observers = {}
|
||||
|
||||
@ -12,7 +17,7 @@ def watch(script, callback):
|
||||
script_dir = os.path.dirname(os.path.abspath(script.args[0]))
|
||||
script_name = os.path.basename(script.args[0])
|
||||
event_handler = _ScriptModificationHandler(callback, filename=script_name)
|
||||
observer = PollingObserver()
|
||||
observer = Observer()
|
||||
observer.schedule(event_handler, script_dir)
|
||||
observer.start()
|
||||
_observers[script] = observer
|
||||
@ -48,9 +53,5 @@ class _ScriptModificationHandler(PatternMatchingEventHandler):
|
||||
if fnmatch.fnmatch(os.path.basename(modified_filepath), self.filename):
|
||||
self.callback()
|
||||
|
||||
def on_created(self, event):
|
||||
if fnmatch.fnmatch(os.path.basename(event.src_path), self.filename):
|
||||
self.callback()
|
||||
|
||||
__all__ = ["watch", "unwatch"]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user