mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-30 02:03:15 +03:00
Fix type errors in watchdog thread cleanup
- `observer` can be None, if --restart-on-changes was not passed, but the hotkey F2 is pressed. - `is_alive` is a bound method, not a property. It was definitely used like a property in the code I referenced. I didn't fix these type checker errors for a long time because: 1. they never caused actual problems for me, and 2. when adding a type annotation `observer: Observer | None`, Pyright gets even _more_ confused, saying it's Unknown | None instead of BaseObserver | None. The secret trick was to leave it unannotated. 3. Adding parentheses to make it `is_alive()` also made Pyright seem even more confused, saying it was Unknown — until I added the conditional.
This commit is contained in:
parent
ef409f4756
commit
d90449e2de
@ -65,10 +65,11 @@ def restart_program():
|
||||
|
||||
try:
|
||||
try:
|
||||
observer.stop()
|
||||
observer.join(timeout=1)
|
||||
if observer.is_alive:
|
||||
print("Timed out waiting for file change observer thread to stop.")
|
||||
if observer:
|
||||
observer.stop()
|
||||
observer.join(timeout=1)
|
||||
if observer.is_alive():
|
||||
print("Timed out waiting for file change observer thread to stop.")
|
||||
except RuntimeError as e:
|
||||
# Ignore "cannot join current thread" error
|
||||
# join() might be redundant, but I'm keeping it just in case something with threading changes in the future
|
||||
|
Loading…
Reference in New Issue
Block a user