Skip to content

self.worker.idle.wait() has race-conditions #6

Description

@torotil

In my setup (using python3) the idle event doesn't seem to work. There seems to be a race condition in the event handling. Example:

execute_some_task.delay()
self.worker.idle.wait()
# something else

This doesn't work for me because self.worker.idle.wait() is executed before the idle event is cleared and thus passes immediately. That's because the events are not handled in the same thread as the call to delay(), thus the order in which the call the wait() and the call to idle.clear() are executed is undefined.

There's actually is a simple way to make those events work: use a simple (lock-protected) counter for the currently running tasks. Increment it on signal.after_task_sent and decrement it on signal.task_postrun.

signal.after_task_sent is guaranteed to run in the same thread as the call to delay.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions