Skip to content

Commit b1d458f

Browse files
committed
Add no buffering and file flush() to cache_lock()
1 parent e72ef63 commit b1d458f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mbed/mbed.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ def cache_lock(self, url):
13561356
if os.path.isfile(lock_file):
13571357
try:
13581358
# lock file exists, but we need to check pid as well in case the process died
1359-
with open(lock_file, 'r') as f:
1359+
with open(lock_file, 'r', 0) as f:
13601360
pid = f.read(8)
13611361
if pid and int(pid) != os.getpid():
13621362
if self.pid_exists(pid):
@@ -1373,8 +1373,10 @@ def cache_lock(self, url):
13731373
break
13741374

13751375
if can_lock:
1376-
with open(lock_file, 'wb') as f:
1376+
with open(lock_file, 'wb', 0) as f:
13771377
f.write(str(os.getpid()))
1378+
f.flush()
1379+
13781380
else:
13791381
error("Exceeded 5 minutes limit while waiting for other process to finish caching")
13801382
except Exception:
@@ -1387,7 +1389,7 @@ def cache_unlock(self, url):
13871389
lock_file = os.path.join(cpath, '.lock')
13881390
if os.path.isfile(lock_file):
13891391
try:
1390-
with open(lock_file) as f:
1392+
with open(lock_file, 'r', 0) as f:
13911393
pid = f.read(8)
13921394
if int(pid) == os.getpid():
13931395
os.remove(lock_file)

0 commit comments

Comments
 (0)