Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.3k
Hot reload#362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Hot reload #362
Changes from all commits
335e03857235335b10597cc6c21c493f99d23882f5ab5333013202e594bf7c07c77bc88c993fa631da7b08bbdc1410865e46383d11e4eae6e714af3d74498f494243e1ae7dcaf22ea7d353d79c4654e5fbeadd63407e24c63033effb26306927d69bd410c9cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import collections | ||
| import os | ||
| import re | ||
| import time | ||
| def watch(folders, on_change, pattern=None, sleep_time=0.1): | ||
| pattern = re.compile(pattern) if pattern else None | ||
| watched = collections.defaultdict(lambda: -1) | ||
| def walk(): | ||
| walked = [] | ||
| for folder in folders: | ||
| for current, _, files, in os.walk(folder): | ||
| for f in files: | ||
| if pattern and not pattern.search(f): | ||
| continue | ||
| path = os.path.join(current, f) | ||
| info = os.stat(path) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. os.path.getmtime might be cleaner here. I thought there was platform dependence issue at first (since otherwise why would they even implement ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, some methods in that module seems to be wrapper around Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍, either way is good, just seemed a bit strange, seems to break ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the | ||
| new_time = info.st_mtime | ||
| if new_time > watched[path] > 0: | ||
| on_change(path, new_time, False) | ||
| watched[path] = new_time | ||
| walked.append(path) | ||
| # Look for deleted files | ||
| for w in [x for x in watched.keys() if x not in walked]: | ||
| del watched[w] | ||
| on_change(w, -1, True) | ||
| while True: | ||
| walk() | ||
| time.sleep(sleep_time) | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat, didn't know you could do this.