I have a python script where I'm using the Chrome selenium driver. Sometimes it crashes, but I haven't found a cause yet. Apparently, it's due to Xvfb
.
Here's how I initialize a driver:
display = Display(visible=0, size=(800, 600))
display.start()
chr_opt = webdriver.ChromeOptions()
chr_opt.add_argument("--no-sandbox")
chr_opt.add_argument("--user-agent={}".format(USER_AGENT))
drv = webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=chr_opt)
Here's what I have in logs:
DEBUG:easyprocess:param: "['Xvfb', '-help']"
DEBUG:easyprocess:command: ['Xvfb', '-help']
DEBUG:easyprocess:joined command: Xvfb -help
DEBUG:easyprocess:process was started (pid=19432)
DEBUG:easyprocess:process has ended
DEBUG:easyprocess:return code=0
DEBUG:easyprocess:stdout=
DEBUG:easyprocess:stderr=use: X [:<display>] [option]
-a # default pointer acceleration (factor)
-ac disable access control restrictions
-audit int set audit trail level
-auth file select authorization file
[.............................skipped ..............................]
[.............................skipped ..............................]
-whitepixel n pixel value for white
-fbdir directory put framebuffers in mmap'ed files in directory
-shmem put framebuffers in shared memory
DEBUG:easyprocess:param: "['xauth', '-h']"
DEBUG:easyprocess:command: ['xauth', '-h']
DEBUG:easyprocess:joined command: xauth -h
DEBUG:easyprocess:process was started (pid=19433)
DEBUG:easyprocess:process has ended
DEBUG:easyprocess:return code=1 <------------------------ why? 1 means "error", doesn't?
DEBUG:easyprocess:stdout=
DEBUG:easyprocess:stderr=usage: xauth [-options ...] [command arg ...]
where options include:
-f authfilename name of authority file to use
-v turn on extra messages
-q turn off extra messages
-i ignore locks on authority file
-b break locks on authority file
-V show version number of xauth
and commands have the following syntax:
add dpyname protoname hexkey add entry
exit save changes and exit program
extract filename dpyname... extract entries into file
[.............................skipped ..............................]
[.............................skipped ..............................]
source filename read commands from file
version show version number of xauth
? list available commands
generate dpyname protoname [options] use server to generate entry
options are:
timeout n authorization expiration time in seconds
trusted clients using this entry are trusted
untrusted clients using this entry are untrusted
group n clients using this entry belong to application group n
data hexkey auth protocol specific data needed to generate the entry
A dash may be used with the "merge" and "source" to read from the
standard input. Commands beginning with "n" use numeric format.
DEBUG:easyprocess:param: "['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1054']"
DEBUG:easyprocess:command: ['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1054']
DEBUG:easyprocess:joined command: Xvfb -br -nolisten tcp -screen 0 800x600x24 :1054
DEBUG:easyprocess:param: "['xauth', '-h']"
DEBUG:easyprocess:command: ['xauth', '-h']
DEBUG:easyprocess:joined command: xauth -h
DEBUG:easyprocess:process was started (pid=19434)
DEBUG:easyprocess:process has ended
DEBUG:easyprocess:return code=1 <------------------------ why? 1 means "error", doesn't?
DEBUG:easyprocess:stdout=
DEBUG:easyprocess:stderr=usage: xauth [-options ...] [command arg ...]
where options include:
-f authfilename name of authority file to use
-v turn on extra messages
-q turn off extra messages
-i ignore locks on authority file
-b break locks on authority file
-V show version number of xauth
and commands have the following syntax:
add dpyname protoname hexkey add entry
exit save changes and exit program
extract filename dpyname... extract entries into file
help [topic] print help
info print information about entries
[.............................skipped ..............................]
[.............................skipped ..............................]
source filename read commands from file
version show version number of xauth
? list available commands
generate dpyname protoname [options] use server to generate entry
options are:
timeout n authorization expiration time in seconds
trusted clients using this entry are trusted
untrusted clients using this entry are untrusted
group n clients using this entry belong to application group n
data hexkey auth protocol specific data needed to generate the entry
A dash may be used with the "merge" and "source" to read from the
standard input. Commands beginning with "n" use numeric format.
DEBUG:easyprocess:param: "['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1055']"
DEBUG:easyprocess:command: ['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '800x600x24', ':1055']
DEBUG:easyprocess:joined command: Xvfb -br -nolisten tcp -screen 0 800x600x24 :1055
DEBUG:easyprocess:process was started (pid=19435)
DEBUG:pyvirtualdisplay.abstractdisplay:DISPLAY=:1055
DEBUG:selenium.webdriver.remote.remote_connection:POST http://127.0.0.1:35260/session {"desiredCapabilities": {"platform": "ANY", "browserName": "chrome", "chromeOptions": {"extensions": [], "args": ["--no-sandbox", "--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"]}, "javascriptEnabled": true, "version": ""}, "requiredCapabilities": {}}
I wonder, why does Xvfb print all that, is it normal?
Why does it print that into stderr --> DEBUG:easyprocess:stderr=use: X [:<display>] [option]
?
Do I have to deal with it and, if so, how?
Reason for this output: In pyvirtualdisplay package below code is there in xauth.py file which checks if easyprocess is installed or not.
Here -h is used by debug in package which displays the help option for easyprocess and the same is displayed in output. Due to this there will be no issue in your code.
Help is present in debug logger. So if you want to suppress this then just set the logger to INFO level using the below line in your code.
logging.getLogger("easyprocess").setLevel(logging.INFO)
Put the above code before initializing the display(like mentioned below):
I hope it will resolve your problem !