Handle properly a psutil exception. Closes #501

This commit is contained in:
Manuel Cortez 2022-12-13 11:16:10 -06:00
parent a3bc684721
commit 3adc726f33
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790

View File

@ -115,12 +115,13 @@ def check_pid():
if os.path.exists(pidpath): if os.path.exists(pidpath):
with open(pidpath) as fin: with open(pidpath) as fin:
pid = int(fin.read()) pid = int(fin.read())
p = psutil.Process(pid=pid) try:
if p.is_running(): p = psutil.Process(pid=pid)
# Display warning dialog if p.is_running():
commonMessageDialogs.common_error(_("{0} is already running. Close the other instance before starting this one. If you're sure that {0} isn't running, try deleting the file at {1}. If you're unsure of how to do this, contact the {0} developers.").format(application.name, pidpath)) # Display warning dialog
sys.exit(1) commonMessageDialogs.common_error(_("{0} is already running. Close the other instance before starting this one. If you're sure that {0} isn't running, try deleting the file at {1}. If you're unsure of how to do this, contact the {0} developers.").format(application.name, pidpath))
else: sys.exit(1)
except psutil.NoSuchProcess:
commonMessageDialogs.dead_pid() commonMessageDialogs.dead_pid()
# Write the new PID # Write the new PID
with open(pidpath,"w") as cam: with open(pidpath,"w") as cam: