Skip to content

Commit

Permalink
Fix TriblerProcess.is_current_process()
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Jun 7, 2023
1 parent 27e0525 commit faf5fcb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/tribler/core/utilities/process_manager/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ def current_process(cls, kind: ProcessKind,
creator_pid: Optional[int] = None,
manager: Optional[ProcessManager] = None) -> TriblerProcess:
"""Constructs an object for a current process, specifying the PID value of the current process"""
return cls(manager=manager, row_version=0, pid=os.getpid(), kind=kind,
app_version=version_id, started_at=int(time.time()), creator_pid=creator_pid)
pid = os.getpid()
psutil_process = psutil.Process(pid)
started_at = int(psutil_process.create_time())
return cls(manager=manager, row_version=0, pid=pid, kind=kind,
app_version=version_id, started_at=started_at, creator_pid=creator_pid)

def is_current_process(self) -> bool:
"""Returns True if the object represents the current process"""
Expand Down Expand Up @@ -169,8 +172,9 @@ def is_running(self):
if status == psutil.STATUS_ZOMBIE:
return False

psutil_process_create_time = psutil_process.create_time()
psutil_process_create_time = int(psutil_process.create_time())
if psutil_process_create_time > self.started_at:
# The same PID value was reused for a new process, so the previous process is not running anymore
return False

return True
Expand Down

0 comments on commit faf5fcb

Please sign in to comment.