So I have the following script that I'm running in a Docker container:
#!/bin/bash
# silencing matplotlib warning
MPLCONFIGDIR="/tmp"
export MPLCONFIGDIR
# Virtual display
export DISPLAY=:0
Xvfb :0 -screen 0 1024x768x24
# my python module is called at this point
The first time I run the script, there seems to be a process that gets stuck: I don't know what's happening behind the terminal, I just have a blank line waiting forever. If I do ctrl+x the process seems to exit and the rest of the script (my python module) is executed just fine.
The second time I run the same script, I get the following error:
_XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed
_XSERVTransMakeAllCOTSServerListeners: server already running
(EE)
Fatal server error:
(EE) Cannot establish any listening sockets - Make sure an X server isn't already running(EE)
Then everything seems to run fine, but I would like to get rid of this warning/error and this weird ctrl+x. Any idea how to proceed?
The issues is that Xvfb :0 -screen 0 1024x768x24
is a blocking command.
To run a blocking command in the background, append &
to the end of the command:
Xvfb :0 -screen 0 1024x768x24 &
This will run the command in the background without blocking the execution of the rest of your script.