#🔒 watchdog going crazy after replacing process image

11 messages · Page 1 of 1 (latest)

raven cedar
#

I'm using the following code to detect changes in my config, which then restarts the app by replacing the process with a new instance of itself:

import os
import sys
import watchdog.events
import watchdog.observers


class _ConfigUpdateHandler(watchdog.events.FileSystemEventHandler):
    def on_modified(self, event: watchdog.events.FileSystemEvent) -> None:
        if event.src_path.endswith("config.json"):
            os.execl(sys.executable, sys.executable, *sys.argv) 


def run_update_listener():
    observer = watchdog.observers.Observer()
    observer.schedule(_ConfigUpdateHandler(), ".")
    observer.start()

This works fine. If I do python3.11 main.py and then save the config.json file, it does restart the app. But here comes the weird part: If I ctrl+c my app, and then do python3.11 main.py again, it spams the on_modified event, ~once per second. I can't even cancel that with ctrl+c, it's stuck in a boot loop. I have no idea why, is that a bug with watchdog? Is it because I apruptly replace the process?

digital oysterBOT
#

@raven cedar

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

unreal tangle
#

then don't ctrl c lol burh i think the watch dog is sensitive about ctrl c so some can't copy your data

#

try having a confrimation that it's you burh i don't really know your os if u a ubuntu or windows

raven cedar
#

It's windows. I can't really rely on "don't ctrl+c" because well that's what I do when stopping the program while development

unreal tangle
#

like explain fam

#

send ss

raven cedar
#

I'm not sure I understand what you mean

#

When having replaced the process image at least once and then stopping the process by keyboard interrupt, watchdog keeps detecting a modification once per second

digital oysterBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.