Typographical errors in example
jsf80238 opened this issue · comments
Hello, on https://pypi.python.org/pypi/stopit the example shows "status" but I believe "state" is desired. Also, "mgr" is sometimes spelled "mrg". The example that worked for me:
import stopit
import time
...
with stopit.ThreadingTimeout(3) as to_ctx_mgr:
assert to_ctx_mgr.state == to_ctx_mgr.EXECUTING
# Something potentially very long but which
time.sleep(2)
OK, let's check what happened
if to_ctx_mgr.state == to_ctx_mgr.EXECUTED:
# All's fine, everything was executed within 10 seconds
print("good")
elif to_ctx_mgr.state == to_ctx_mgr.EXECUTING:
# Hmm, that's not possible outside the block
print("not possible")
elif to_ctx_mgr.state == to_ctx_mgr.TIMED_OUT:
# Eeek the 10 seconds timeout occurred while executing the block
print("timeout")
elif to_ctx_mgr.state == to_ctx_mgr.INTERRUPTED:
# Oh you raised specifically the TimeoutException in the block
print("timeout exception raised")
elif to_ctx_mgr.state == to_ctx_mgr.CANCELED:
# Oh you called to_ctx_mgr.cancel() method within the block but it
# executed till the end
print("canceled")
else:
# That's not possible
pass
Thank you for providing this software to the world! I appreciate it.
Hi, many thanks for this. I'll change the README accordiingly but won't make a release since it's a "documentation bug".