This piece of code, taken from the documentation, could be less verbose using a context manager.
Current code:
observer.start()
try:
while True:
time.sleep(1)
finally:
observer.stop()
observer.join()
Proposition:
with observer:
while True:
time.sleep(1)
Both codes will remain valid, of course.