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.
If you are waiting for some action to be completed, you can simulate a minor mouse movement in a new thread. This will prevent system from sleep.
Automation using Pyautogui