mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
don't need workaround
This commit is contained in:
parent
ddc6be60c0
commit
f26e779a64
@ -5,7 +5,6 @@ Process IDentification-related helpers.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
from attrs import frozen
|
|
||||||
|
|
||||||
# the docs are a little misleading, but this is either WindowsFileLock
|
# the docs are a little misleading, but this is either WindowsFileLock
|
||||||
# or UnixFileLock depending upon the platform we're currently on
|
# or UnixFileLock depending upon the platform we're currently on
|
||||||
@ -81,7 +80,7 @@ def check_pid_process(pidfile: FilePath) -> None:
|
|||||||
# a short timeout is fine, this lock should only be active
|
# a short timeout is fine, this lock should only be active
|
||||||
# while someone is reading or deleting the pidfile .. and
|
# while someone is reading or deleting the pidfile .. and
|
||||||
# facilitates testing the locking itself.
|
# facilitates testing the locking itself.
|
||||||
with FileLock(_CouldBeBytesPath(lock_path.path), timeout=2):
|
with FileLock(lock_path.path, timeout=2):
|
||||||
# check if we have another instance running already
|
# check if we have another instance running already
|
||||||
if pidfile.exists():
|
if pidfile.exists():
|
||||||
pid, starttime = parse_pidfile(pidfile)
|
pid, starttime = parse_pidfile(pidfile)
|
||||||
@ -121,7 +120,7 @@ def cleanup_pidfile(pidfile: FilePath) -> None:
|
|||||||
all goes wrong, `CannotRemovePidFile` is raised.
|
all goes wrong, `CannotRemovePidFile` is raised.
|
||||||
"""
|
"""
|
||||||
lock_path = _pidfile_to_lockpath(pidfile)
|
lock_path = _pidfile_to_lockpath(pidfile)
|
||||||
with FileLock(_CouldBeBytesPath(lock_path.path)):
|
with FileLock(lock_path.path):
|
||||||
try:
|
try:
|
||||||
pidfile.remove()
|
pidfile.remove()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -131,15 +130,3 @@ def cleanup_pidfile(pidfile: FilePath) -> None:
|
|||||||
err=e,
|
err=e,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@frozen
|
|
||||||
class _CouldBeBytesPath(object):
|
|
||||||
"""
|
|
||||||
Sneak bytes past `FileLock.__init__`.
|
|
||||||
|
|
||||||
See https://github.com/tox-dev/py-filelock/issues/258
|
|
||||||
"""
|
|
||||||
_path: str | bytes
|
|
||||||
|
|
||||||
def __fspath__(self) -> str | bytes:
|
|
||||||
return self._path
|
|
||||||
|
Loading…
Reference in New Issue
Block a user