diff --git a/src/client.py b/src/client.py --- a/src/client.py +++ b/src/client.py @@ -8,7 +8,7 @@ import config as conf import stats from util import Progress from hashtree import HashTree,hashBlock -from netnode import BaseConnection,NetNode,FailedConnection +from netnode import BaseConnection,NetNode,FailedConnection,LockedException class DeniedConnection(Exception): pass @@ -125,8 +125,13 @@ class Client(NetNode): log.info("closing session...") dataFile.close() - def pullData(self,blocksToTransfer): - self._lock() + def pullData(self,blocksToTransfer,ignoreLock=False): + if not ignoreLock: + try: + self._lock() + except LockedException: + print("The file is locked. Either (a) there's another pull going on (then wait or kill it), or (b) a previous pull ended prematurely and the file is probably corrupt (then repeat pull with -f for force).") + return log.info(blocksToTransfer) dataFile=open(self._filename, mode="rb+") i1=-1