Changeset - 870c5c6c334f
[Not reviewed]
default
0 3 0
Laman - 5 years ago 2020-05-24 21:55:14

reacquiring old locks
3 files changed with 15 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/client.py
Show inline comments
 
@@ -166,8 +166,10 @@ class Client(NetNode):
 
					self._new_leaves[i+self._tree.leaf_start] = hash_block(block)
 

	
 
					t = datetime.now().timestamp()
 
					if t-last_flushed >= 60 and self._tree_file:
 
					if t-last_flushed >= 60:
 
						if self._tree_file:
 
						self._update_tree()
 
						self._refresh_lock()
 
						last_flushed = t
 

	
 
				stats.log_transferred_block()
src/netnode.py
Show inline comments
 
import os
 
from datetime import datetime
 
import socket
 
import logging as log
 

	
 
@@ -62,7 +63,15 @@ class NetNode:
 
			f = open(lock_file, "x")
 
			f.close()
 
		except FileExistsError:
 
			stat = os.stat(lock_file)
 
			dt = datetime.now().timestamp()-stat.st_mtime
 
			if dt<5*60:
 
			raise LockedException()
 
			log.warning("Found an old lock file ({0}s), ignoring it.".format(round(dt)))
 
			self._refresh_lock()
 

	
 
	def _refresh_lock(self):
 
		os.utime(lock_file)
 

	
 
	def _unlock(self):
 
		os.remove(lock_file)
src/server.py
Show inline comments
 
@@ -150,8 +150,10 @@ class Server(NetNode):
 
				self._new_leaves[k+self._tree.leaf_start] = hash_block(block)
 

	
 
		t = datetime.now().timestamp()
 
		if t-self._last_flushed>=60 and self._tree_file:
 
		if t-self._last_flushed>=60:
 
			if self._tree_file:
 
			self._update_tree()
 
			self._refresh_lock()
 
			self._last_flushed = t
 

	
 
		return ({"command": "ack", "index": indices},)
0 comments (0 inline, 0 general)