Separate lock file instad of log file locking
This commit is contained in:
parent
4ac933fa29
commit
484659fc3f
2 changed files with 7 additions and 2 deletions
|
@ -44,7 +44,8 @@ if config.action == "main":
|
||||||
from util import helper
|
from util import helper
|
||||||
log_file_path = "%s/debug.log" % config.log_dir
|
log_file_path = "%s/debug.log" % config.log_dir
|
||||||
try:
|
try:
|
||||||
helper.openLocked(log_file_path, "a")
|
lock = helper.openLocked("%s/lock.pid" % config.data_dir, "w")
|
||||||
|
lock.write("%s" % os.getpid())
|
||||||
except IOError as err:
|
except IOError as err:
|
||||||
print "Can't lock %s file, your ZeroNet client is probably already running, exiting... (%s)" % (log_file_path, err)
|
print "Can't lock %s file, your ZeroNet client is probably already running, exiting... (%s)" % (log_file_path, err)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
@ -55,7 +56,7 @@ if config.action == "main":
|
||||||
os.rename("%s/debug.log" % config.log_dir, "%s/debug-last.log" % config.log_dir)
|
os.rename("%s/debug.log" % config.log_dir, "%s/debug-last.log" % config.log_dir)
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='[%(asctime)s] %(levelname)-8s %(name)s %(message)s',
|
format='[%(asctime)s] %(levelname)-8s %(name)s %(message)s',
|
||||||
level=logging.DEBUG, stream=helper.openLocked(log_file_path, "a")
|
level=logging.DEBUG, stream=open(log_file_path, "a")
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
log_file_path = "%s/cmd.log" % config.log_dir
|
log_file_path = "%s/cmd.log" % config.log_dir
|
||||||
|
|
|
@ -39,6 +39,10 @@ def openLocked(path, mode="w"):
|
||||||
import fcntl
|
import fcntl
|
||||||
f = open(path, mode)
|
f = open(path, mode)
|
||||||
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
|
elif os.name == "nt":
|
||||||
|
import msvcrt
|
||||||
|
f = open(path, mode)
|
||||||
|
msvcrt.locking(f.fileno(), msvcrt.LK_NBLCK, -1)
|
||||||
else:
|
else:
|
||||||
f = open(path, mode)
|
f = open(path, mode)
|
||||||
return f
|
return f
|
||||||
|
|
Loading…
Reference in a new issue