mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 22:03:13 -07:00
Fix pidfile access
This commit is contained in:
parent
cd5d9c4bc2
commit
fc3d6a5744
1 changed files with 6 additions and 12 deletions
|
@ -21,9 +21,9 @@ if os.name == 'nt':
|
||||||
class WindowsProcess:
|
class WindowsProcess:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.mutex = None
|
self.mutex = None
|
||||||
self.mutexname = 'nzbtomedia_{pid}'.format(
|
# {D0E858DF-985E-4907-B7FB-8D732C3FC3B9}
|
||||||
pid=core.PID_FILE.replace('\\', '/'),
|
_path_str = os.fspath(core.PID_FILE).replace('\\', '/')
|
||||||
) # {D0E858DF-985E-4907-B7FB-8D732C3FC3B9}'
|
self.mutexname = f'nzbtomedia_{_path_str}'
|
||||||
self.CreateMutex = CreateMutex
|
self.CreateMutex = CreateMutex
|
||||||
self.CloseHandle = CloseHandle
|
self.CloseHandle = CloseHandle
|
||||||
self.GetLastError = GetLastError
|
self.GetLastError = GetLastError
|
||||||
|
@ -80,21 +80,15 @@ class PosixProcess:
|
||||||
|
|
||||||
if not self.lasterror:
|
if not self.lasterror:
|
||||||
# Write my pid into pidFile to keep multiple copies of program from running
|
# Write my pid into pidFile to keep multiple copies of program from running
|
||||||
try:
|
with self.pidpath.open(mode='w') as fp:
|
||||||
fp = open(self.pidpath, 'w')
|
fp.write(os.getpid())
|
||||||
fp.write(str(os.getpid()))
|
|
||||||
fp.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return self.lasterror
|
return self.lasterror
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if not self.lasterror:
|
if not self.lasterror:
|
||||||
if self.lock_socket:
|
if self.lock_socket:
|
||||||
self.lock_socket.close()
|
self.lock_socket.close()
|
||||||
if os.path.isfile(self.pidpath):
|
self.pidpath.unlink(missing_ok=True)
|
||||||
os.unlink(self.pidpath)
|
|
||||||
|
|
||||||
|
|
||||||
ProcessType = typing.Type[typing.Union[PosixProcess, WindowsProcess]]
|
ProcessType = typing.Type[typing.Union[PosixProcess, WindowsProcess]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue