mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-22 06:11:37 +03:00
Try to clean up the file change observer when restarting
This is all theoretical.
This commit is contained in:
parent
3c2ff7b3d8
commit
509618c1be
11
paint.py
11
paint.py
@ -28,6 +28,8 @@ from windows import Window, DialogWindow
|
||||
from localization.i18n import get as _, load_language
|
||||
|
||||
|
||||
observer = None
|
||||
|
||||
def restart_program():
|
||||
"""Restarts the current program, after file objects and descriptors cleanup"""
|
||||
|
||||
@ -40,6 +42,14 @@ def restart_program():
|
||||
except Exception as e:
|
||||
print("Error stopping application mode. The command line may not work as expected.", e)
|
||||
|
||||
try:
|
||||
observer.stop()
|
||||
observer.join(timeout=1)
|
||||
if observer.is_alive:
|
||||
print("Timed out waiting for file change observer thread to stop.")
|
||||
except Exception as e:
|
||||
print("Error stopping file change observer:", e)
|
||||
|
||||
try:
|
||||
p = psutil.Process(os.getpid())
|
||||
for handler in p.open_files() + p.connections():
|
||||
@ -64,6 +74,7 @@ class RestartHandler(PatternMatchingEventHandler):
|
||||
|
||||
def restart_on_changes():
|
||||
"""Restarts the current program when a file is changed"""
|
||||
global observer
|
||||
observer = Observer()
|
||||
observer.schedule(RestartHandler(
|
||||
# Don't need to restart on changes to .css, since Textual will reload them in --dev mode
|
||||
|
Loading…
Reference in New Issue
Block a user