Skip to content

stuck in a reload loop #565

Description

@CDU-Ge

Taskiq version

0.12.1

Python version

Python 3.12

OS

Linux

What happened?

In taskiq/cli/watcher.py, only the event types "opened" and "closed" were ignored. The "closed_no_write" event triggered an endless loop.

this is code:

class FileWatcher:  # pragma: no cover
    """Filewatcher that watches for filesystem changes."""
    ...
    def dispatch(self, event: FileSystemEvent) -> None:
        """
        React to event.

        This function checks whether we need to
        react to event and calls callback if we do.

        :param event: incoming fs event.
        """
        if event.is_directory:
            return
        if event.event_type in {"opened", "closed"}:
            return
        if ".git" in event.src_path:
            return
        try:
            if self.gitignore and self.gitignore(event.src_path):
                return
        except Exception as exc:
            logger.info(
                f"Cannot check path `{event.src_path!r}` in gitignore. Cause: {exc}",
            )
            return

        logger.debug(f"File changed. Event: {event}")
        self.callback(**self.callback_kwargs)

Relevant log output

Broker initialization code

Activity

  1. CDU-Ge commented on Dec 9, 2025

    @CDU-Ge
    Author

    Perhaps adding an environment variable TASKIQ_RELOAD_IGNORE_EVENT_TYPE would be a good idea.

  2. sebastianjanisch commented on Dec 9, 2025

    @sebastianjanisch

    I am looking at the same issue. For me it is close no write events on __pycache__ files which live under my monitored folders.
    I am getting around this for now by monkey patching the FileWatcher dispatch method.

  3. s3rius commented on Dec 16, 2025

    @s3rius
    Member

    Okay. Seems like like something has changed in the way we watch for files. Maybe lib update.

    As a workaround you can add --reload-dir {project_dir}. This workaround will solve your issue. But I still need to look into it to resolve this problem without any arguments.

  4. gegnew commented on Dec 20, 2025

    @gegnew

    This is also happening for me on __pycache__ files, and the file watcher doesn't seem to be respecting my .gitignore.

    taskiq_worker-1     | [2025-12-20 18:00:04,902][taskiq.worker][DEBUG  ][worker-0] UVLOOP found. Using it as async runner
    taskiq_worker-1     | [2025-12-20 18:00:04,903][taskiq.worker][DEBUG  ][worker-0] Inserting /app in sys.path
    taskiq_worker-1     | [2025-12-20 18:00:04,905][taskiq.worker][DEBUG  ][MainProcess] File changed. Event: FileClosedNoWriteEvent(src_path='app/__pycache__/__init__.cpython-313.pyc', dest_path='', event_type='closed_no_write', is_directory=False, is_synthetic=False)
    taskiq_worker-1     | [2025-12-20 18:00:04,905][taskiq.process-manager][INFO   ][MainProcess] Scheduled workers reload.
    taskiq_worker-1     | [2025-12-20 18:00:04,907][taskiq.worker][DEBUG  ][MainProcess] File changed. Event: FileClosedNoWriteEvent(src_path='app/tasks/__pycache__/tk.cpython-313.pyc', dest_path='', event_type='closed_no_write', is_directory=False, is_synthetic=False)
    taskiq_worker-1     | [2025-12-20 18:00:04,907][taskiq.process-manager][INFO   ][MainProcess] Scheduled workers reload.
    taskiq_worker-1     | [2025-12-20 18:00:04,952][taskiq.worker][DEBUG  ][MainProcess] File changed. Event: FileClosedNoWriteEvent(src_path='app/__pycache__/settings.cpython-313.pyc', dest_path='', event_type='closed_no_write', is_directory=False, is_synthetic=False)
    taskiq_worker-1     | [2025-12-20 18:00:04,953][taskiq.process-manager][INFO   ][MainProcess] Scheduled workers reload.
    taskiq_worker-1     | [2025-12-20 18:00:04,965][taskiq.worker][DEBUG  ][worker-0] Inserting /app in sys.path
    taskiq_worker-1     | [2025-12-20 18:00:04,965][taskiq.worker][DEBUG  ][worker-0] Initialize receiver.
    taskiq_worker-1     | [2025-12-20 18:00:04,966][taskiq.worker][DEBUG  ][worker-0] Inserting /app in sys.path
    taskiq_worker-1     | [2025-12-20 18:00:04,967][taskiq.worker][DEBUG  ][MainProcess] File changed. Event: FileClosedNoWriteEvent(src_path='app/__pycache__/main.cpython-313.pyc', dest_path='', event_type='closed_no_write', is_directory=False, is_synthetic=False)
    taskiq_worker-1     | [2025-12-20 18:00:04,967][taskiq.process-manager][INFO   ][MainProcess] Scheduled workers reload.
    taskiq_worker-1     | [2025-12-20 18:00:05,005][root][DEBUG  ][MainProcess] Got event: ReloadOneAction(worker_num=0, is_reload_all=True)
    taskiq_worker-1     | [2025-12-20 18:00:05,005][root][DEBUG  ][MainProcess] Got event: ReloadOneAction(worker_num=0, is_reload_all=True)
    taskiq_worker-1     | [2025-12-20 18:00:05,005][root][DEBUG  ][MainProcess] Got event: ReloadOneAction(worker_num=0, is_reload_all=True)
    taskiq_worker-1     | [2025-12-20 18:00:05,005][root][DEBUG  ][MainProcess] Got event: ReloadOneAction(worker_num=0, is_reload_all=True)
    
    
  5. epicwhale commented on Dec 24, 2025

    @epicwhale

    Think I'm running into the same issue as @gegnew #574

  6. albireox commented on Jan 15, 2026

    @albireox

    It seems #568 fixes this issue. Any chances of having a point release with this fix soon?

  7. mike-cgr commented on Apr 16, 2026

    @mike-cgr

    Confirmed this affects 0.12.1 on Linux with an OrbStack Docker bind mount.
    I managed to work around it by monkey-patching FileWatcher.dispatch to add "closed_no_write" to the filtered event types.
    The --reload-dir workaround doesn't fully resolve it as the events still originate from within the specified directory.

    Looking forward to a 0.12.2 release. Cheers.

  8. s3rius commented on May 4, 2026

    @s3rius
    Member

    The release has happened and this issue should be resolved. Please verify the fix and consider closing if the problem is gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions