Created
October 22, 2019 21:39
-
-
Save 1st1/d9860cbf6fe2e5d243e695809aea674c 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
import time | |
import threading | |
def generator(): | |
try: | |
print('STARTED') | |
time.sleep(5) | |
yield 1 | |
finally: | |
print('FINALIZED') | |
def close_it(): | |
print('Atttempting to close') | |
try: | |
gen.close() | |
except BaseException as ex: | |
print(f"Couldn't close {type(ex).__name__}: {ex}") | |
else: | |
print('Closed!') | |
gen = generator() | |
threading.Timer(1, close_it).start() | |
gen.send(None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: