Search code examples
pythonazurepyautogui

How to run graphical automation in Azure VM (or similar)


I made a python script that runs a graphical automation using pyautogui (mouse movements) over a huge number of PDFs. The automation appears to need an active display, for the mouse movements and the PDF to be opened. If I connect to the Azure VM (with Windows OS) with SSH and start the python script, I get an error from pyautogui as below:

pyautogui.FailSafeException:
    PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen.
    To disable this fail-safe, set pyautogui.FAILSAFE to False.
    DISABLING FAIL-SAFE IS NOT RECOMMENDED.

I have tried with the failsafe disable and still it doesn't work. As I have read, this happens because there is no active display opened.

If I connect to the VM using RDP, the automation starts and works as expect until I minimize or close the window. When I do that I get the same failsafe error from pyautogui. But I cannot keep the window open, because I would need to start the same automation on 16 more VMs.

  1. Is there a way to run such graphical automations in Azure VMs or any other similar solution? Docker maybe?

  2. Is there any solution to run or host VM machines with permanent active display opened? Is something like this possible?


Solution

  • I ended up using Virtual Box.

    I first created one VM with the needed software and files. You can start the VM in headless mode. Then show the VM in order to log in to Windows and start the automation script. Then you can close the VM window and let it run in the background. The graphical automation will still run ok in that case. PyAutoGUI won't crash as if there were no active display.

    I cloned the original VM 16 times and split the work evenly between the VMs.

    Using ssh I am able to connect to each VM and monitor the status of the automations.

    It would be great if there were a solution similar to kubernetes that could help with the deployment of such automations and with the monitoring of the status, but until then this is ok.