Skip to content

Instantly share code, notes, and snippets.

@Winand
Created June 1, 2016 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Winand/9f04c5b40bc47a57b0a97f52aacb4041 to your computer and use it in GitHub Desktop.
Save Winand/9f04c5b40bc47a57b0a97f52aacb4041 to your computer and use it in GitHub Desktop.
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