Created
June 1, 2016 11:26
-
-
Save Winand/9f04c5b40bc47a57b0a97f52aacb4041 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WaitForModification(): | |
"wait for /path/ file to be modified before exiting /with/ block" | |
def __init__(self, path): | |
self.path = path | |
self.mtime = not os.path.exists(path) or os.path.getmtime(path) | |
def __enter__(self): | |
pass | |
def __exit__(self, *args): | |
while True: | |
try: | |
if os.path.getmtime(self.path)!=self.mtime: break | |
except: pass | |
time.sleep(0.01) #<------------------ | |
... | |
with self.WaitForModification(fpath): | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment