Forums

Schdule a file to run in a virtual environment and with xvfb.

I'm trying to get a file to run in a virtual environment and with xvfb. I know putting /home/aaleks/.virtualenvs/myvirtualenv/bin/python2.7 will run it in a virtual environment but how do I also run xvfb with it?

Thanks!

Whether it's in a virtualenv or not, the Python code stays the same. Have a look at this forum thread

Yes, but if I try to put xvfb-run after /home/aaleks/.virtualenvs/myvirtualenv/bin/python2.7 it try to look that up as a file. How do I put it in the schedule box so that a python file runs wiht xvfb.

Also if I try to schedule run a python file with xvfb I get "xvfb-run: error: Xvfb failed to start".

So it should be something like

xvfb-run /home/aaleks/.virtualenvs/myvirtualenv/bin/python2.7 /path/to/my_selenium_tests.py

Is this what you were doing?

Yes, that's what I have but I keep getting the error "xvfb-run: error: Xvfb failed to start".

What happens if you paste the exact command that's in your scheduled task into a Bash console?

It runs with no problems.

That's very strange. I see that you don't have any scheduled tasks set up right now; could you set one up to run the command, and let it run? Then perhaps I can find something in the server logs.

Ok, I added some and let them run. What's strange is the first two runs actually worked but the last two I tried gave me the xvfb error.

Hmm. Maybe there's a problem with another task also running Xvfb at the same time, and they're both trying to grab the same display number? Try adding the "-a" flag to your command line and see if that helps.

Thanks! It looks like that worked. I noticed it's using display 100 instead of 99 which is was using before. I don't have anything else running so I don't know what would be using 99 but I guess it doesn't really matter now that it's working.

Excellent, thanks for confirming! We'll have to remember that one. If you don't specify -a it will always try to take #99, but with the flag it will try 99, then if that's already in use, it will try 100, and so on.