0

I initialized a webdriver object with celery but reported this error on windows.

set_nonblocking() on a file object with no setblocking() method (Windows pipes don't support non-blocking I/O)

Code trial:

celery_app = Celery()
celery_app.config_from_object('config.celeryconfig')
from celery import Task
from selenium import webdriver
eventlet.monkey_patch(os=False)



class GetDriver(Task):
    test = 'test'
    chromedriver_path = "chromedriver.exe"

    driver = webdriver.Chrome(executable_path=chromedriver_path)

@celery_app.task(base=GetDriver, bind=True)
def demo(self, params):
    print(params)
    print(self.test)

Can cellery initialize a webdriver object at initialization?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
lccc
  • 1

3 Answers3

0
celery_app = Celery()
celery_app.config_from_object('config.celeryconfig')
from celery import Task
from selenium import webdriver
eventlet.monkey_patch(os=False)



class GetDriver(Task):
    test = 'test'
    chromedriver_path = "chromedriver.exe"

    driver = webdriver.Chrome(executable_path=chromedriver_path)

@celery_app.task(base=GetDriver, bind=True)
def demo(self, params):
    print(params)
    print(self.test)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
lccc
  • 1
0

This error message...

set_nonblocking() on a file object with no setblocking() method (Windows pipes don't support non-blocking I/O)

...is observed when the interpreter is unable to locate the ChromeDriver binary while trying to initiate/spawn a new Browsing Context i.e. Chrome Browser session.


In your code block you have used:

chromedriver_path = "chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver_path)

Your program is unable to locate the chromedriver.exe. Hence the error.


Solution

You need to mention the absolute path of the ChromeDriver as follows:

chromedriver_path = r'C:\path\to\chromedriver.exe'
driver = webdriver.Chrome(executable_path=chromedriver_path)

References

You can find a couple of relevant discussions in:


Outro

Non-blocking read on a subprocess.PIPE in python

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-1

Did you add the parameter "-P eventlet" when starting the "celery" service. I encountered the same problem, and then I removed the parameter and the problem was solved.

celery -A proj worker -l info  -P eventlet   (old)
celery -A proj worker -l info
Janebook
  • 1
  • 1