2

I'm running a selenium webdriver in a celery task. However, in some cases, I need to revoke/terminate the celery task. I successfully terminate the celery task using the following

>>> from proj.celery import app
>>> app.control.revoke(task_id, terminate=True)

However, the webdriver remains open when the task is terminated. How can I quit the driver also?

Muhammad Zubair
  • 466
  • 5
  • 17
  • If you keep a reference to your driver you could quit it before you revoke the task. – C. Short Oct 20 '21 at 03:40
  • How can I keep a reference to my driver? btw I'm doing it this way that when I start the task, I store the celery `task_id` in my `db`, and whenever the user asks to revoke it, I revoke the task by getting the `task_id` from the `db` – Muhammad Zubair Oct 20 '21 at 11:10
  • When you start your webdriver keep it stored in a variable that can be passed around like driver = webdriver.Chrome. When you want to revoke your task call driver.quit() – C. Short Oct 21 '21 at 05:04
  • The variable is created inside the task, and I revoke the task from outside the task, so how can I access that driver at revoke time? Maybe if there is some way possible to override the revoke method, then the driver method might be accessible there. However, I have no idea how to override the revoke method. – Muhammad Zubair Oct 21 '21 at 15:52
  • 1
    I see what you mean now. Unfortunately I dont know and I will also have the same issue soon without a solution. If the task had a cleanup function within it that would be helpful but not sure celery does. – C. Short Oct 21 '21 at 21:32

0 Answers0