My system will goes to sleep if there is no keyboard and mouse action for more than 5 min ( I cannot make any changes in sleep time. For security reason it is set to 5 min). 
I am using pyautogui for automation. Pyautogui works in background based on screen resolution by taking keyboard and mouse control. It is taking more than 5 min in my case to complete the execution. After 5 min it going to sleep and keyboard interrupt is generated.
Please let me know is there any solution for these.
One thing I've found to work is running the pyautogui script in a virtual machine, which lets it use the virtual mouse & keyboard. This has the twofold benefit of a. allowing you to do other work while the script is running, and b. the virtual mouse & keyboard are not interrupted with the computer going to sleep.
Hope this helps!
Automation using Pyautogui