'Python keyboard library timing out after a period of time

I have made a really simple application for my daily usage that listens for key right shift on my keyboard and when ever I press the key it types out "0000" where ever I am

this is the code

import keyboard 


def main():
    print('0000\nRSHIFT = 0000 \nCTRL + ESC = EXIT')
    keyboard.add_hotkey('right shift', lambda: keyboard.write('0000') )
    keyboard.wait('esc+ctrl')
    exit(0)

if __name__ == "__main__":
    main()

It works completely fine though after about 2 or 3 minutes It kinda times out to be frank program is still running but neither of keys I press do anything To fix it I usually close the program and rerun it

I also use pyinstaller to generate the exe file for it on WINDOWS:

pyinstaller --onefile 0000.py

how can I fix this ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source