Skip to content

Commit

Permalink
Fix handling of invalid pid file
Browse files Browse the repository at this point in the history
  • Loading branch information
lrineau committed Oct 12, 2023
1 parent a672598 commit 3863f80
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test_cgal.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ def main():
# Setup the pidfile handling
if os.path.isfile(pidfile):
logging.warning('pidfile {} already exists. Killing other process.'.format(pidfile))
with open(pidfile, 'r') as pf:
oldpid = int(pf.read().strip())
try:
with open(pidfile, 'r') as pf:
oldpid = int(pf.read().strip())
os.kill(oldpid, signal.SIGTERM)
# Wait for the process to terminate.
while pid_exists(oldpid):
pass
except OSError:
logging.warning('pidfile {} did contain invalid pid {}.'.format(pidfile, oldpid))
except (OSError, ValueError):
logging.warning('pidfile {} did contain invalid pid.'.format(pidfile))

with open(pidfile, 'w') as pf:
pid = str(os.getpid())
Expand Down

0 comments on commit 3863f80

Please sign in to comment.