I set up a celery environment and released two tasks. One is to open Google Chrome, and the other is a simple addition calculation. There is no problem with the function of addition calculation, but the function of opening the browser reports an error, and the browser cannot be opened.
The error:
File "d:\software\professional\python27\lib\site-packages\selenium\webdriver\common\service.py", line 95, in start (os.path.basename(self.path), self.start_error_message, str(e))) WebDriverException: Message: The executable chromedriver needs to be available in the path. Please see https://sites.google.com/a/chromium.org/chromedriver/home set_nonblocking() on a file object with no setblocking() method (Windows pipes don't support non-blocking I/O)
my code:(tasks.py)
# -*- coding:utf-8 -*-
from selenium import webdriver
import time
from proj.celery import app
import os
@app.task
def chrome_test():
chrome_options = webdriver.ChromeOptions()
driver_path1 = r"chromedriver"
driver_path2 = os.path.join(r"D:\SoftWare\Professional\ChromeDriver", "chromedriver.exe")
# print "try to open chrome..."
driver = webdriver.Chrome(executable_path=driver_path1, options=chrome_options)
# executable_path=driver_path, options=chrome_options
print "open chrome success"
driver.get("https://www.baidu.com/")
time.sleep(1)
print driver
driver.close()
return "success to open chrome..."
@app.task
def add(x, y):
time.sleep(1)
return x+y
if __name__ == "__main__":
chrome_test()
But if I run the function alone, it can work very well.