Browse Source

Write pid to wallet lockfile, display it when lock already in place

master
Kristaps Kaupe 7 years ago
parent
commit
585d2f9033
  1. 15
      jmclient/jmclient/storage.py

15
jmclient/jmclient/storage.py

@ -277,13 +277,16 @@ class Storage(object):
return return
self._lock_file = '{}.lock'.format(self.path) self._lock_file = '{}.lock'.format(self.path)
if os.path.exists(self._lock_file): if os.path.exists(self._lock_file):
with open(self._lock_file, 'r') as f:
locked_by_pid = f.read()
self._lock_file = None self._lock_file = None
raise StorageError("File is currently in use. If this is a " raise StorageError("File is currently in use (locked by pid {}). "
"leftover from a crashed instance you need to " "If this is a leftover from a crashed instance "
"remove the lock file manually") "you need to remove the lock file manually" .
#FIXME: in python >=3.3 use mode xb format(locked_by_pid))
with open(self._lock_file, 'wb'): #FIXME: in python >=3.3 use mode x
pass with open(self._lock_file, 'w') as f:
f.write(str(os.getpid()))
atexit.register(self.close) atexit.register(self.close)

Loading…
Cancel
Save