Skip to content

How to implement terminate_job for eventlet concurrency backend? #3429

Closed

Description

@yrik

As I see terminate_job method implemented only in prefork concurrency backend https://github.com/celery/celery/blob/master/celery/concurrency/prefork.py#L116.

I'm running eventlet based code in the celery task, and to have it properly patched I must use -P eventlet option while starting workers. With this option Celery uses eventlet based TaskPool and patches the code. However, I also need to be able to terminate the task. How could it be possible to write missing terminate_job code?

I have tried with the following code:


class TaskPool(base.BasePool):
    ...
    def on_terminate(self):
        from eventlet import greenthread
        if self._pool is not None:
             greenthread.kill(self.getcurrent())

    def terminate_job(self, pid, signal=None):
        self.terminate()

    def terminate(self):
        self._state = self.TERMINATE
        self.on_terminate()

But it actually does not stop the execution. Plase help with valid approach.

Other option for me is to run celery in prefork mode, which support terminate method, and apply eventlet patch in the task file, but in this case I have an issue with django

DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 140575345698560 and this is thread id 140575293188528.

So I need any method to run eventlet code in the Celery task with the ability to stop it.
Plase advice.

Activity

  1. changed the title [-]How it could be possible to implement `terminate_job` for eventlet concurrency backend?[/-] [+]How it could be possible to implement terminate_job for eventlet concurrency backend?[/+] on Sep 6, 2016
  2. changed the title [-]How it could be possible to implement terminate_job for eventlet concurrency backend?[/-] [+]How to implement terminate_job for eventlet concurrency backend?[/+] on Sep 6, 2016
  3. hostgame commented on Oct 3, 2017

    @hostgame

    Same issue. Is it planned to implement job terminating in pools except prefork?

  4. puzanov commented on Oct 4, 2017

    @puzanov

    Anyone?

  5. added this to the milestone on Dec 20, 2017
  6. auvipy commented on Dec 20, 2017

    @auvipy
    Member

    may be this issue is a guide for fix #3520

  7. reopened this on May 21, 2018
  8. auvipy commented on Aug 12, 2018

    @auvipy
    Member

    closing for lack of response.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions