Replace the Python process with a shell when starting up if a key is pressed during a grace period.
pip install safemodeJust import the library in the first line of your Python script. The grace period can be configured through the SAFEMODE_GRACE_PERIOD environment variable. The default value is 5 seconds.
main.py
import safemode
print('Hello World')Safe mode:
$ python main.py
[safemode] To start a shell, press any key before 5 seconds...
$Normal execution:
$ python main.py
[safemode] To start a shell, press any key before 5 seconds...
[safemode] Starting up normally...
Hello World