Consider using sys.exit()
47
48 if useWebsocket and certificatePath and privateKeyPath:
49 print("X.509 cert authentication and WebSocket are mutual exclusive. Please pick one.")
50 exit(2)51
52 if not useWebsocket and (not certificatePath or not privateKeyPath):
53 print("Missing credentials for authentication.")
Consider using sys.exit()
51
52 if not useWebsocket and (not certificatePath or not privateKeyPath):
53 print("Missing credentials for authentication.")
54 exit(2)55
56 # Port defaults
57 if useWebsocket and not port: # When no port override for WebSocket, default to 443
Description
The exit
or quit
functions don't exist at top-level if python is started with the -S
flag, and will raise an error. Use sys.exit()
instead.
The exit
and quit
functions are actually site.Quitter
objects and are loaded, at interpreter start up, from site.py
.
However, if the interpreter is started with the -S
flag, or a custom site.py
is used then exit
and quit
may not be present.
It is recommended to use sys.exit()
which is built into the interpreter and is guaranteed to be present.
Bad practice
try:
patch_diffs()
except Exception as exc:
print(exc)
exit(1)
Here, exit()
is used and will fail if the python is run with the -S
option.
Recommended
import sys
try:
patch_diffs()
except Exception as exc:
print(exc)
sys.exit(1)
sys.exit()
is guaranteed to work, regardless of the interpreter options.