Use with open(filePath) as f:
instead of f = open(filePath)
in search.py
This commit is contained in:
parent
58f25a114e
commit
d3c87d3b6f
@ -15,7 +15,7 @@ searchOnlyCaptions = pathSearchMessageParts[0] == 'search-only-captions'
|
|||||||
clientFilePath = f'users/{clientId}.txt'
|
clientFilePath = f'users/{clientId}.txt'
|
||||||
|
|
||||||
def write(s):
|
def write(s):
|
||||||
f = open(clientFilePath, 'r+')
|
with open(clientFilePath, 'r+') as f:
|
||||||
try:
|
try:
|
||||||
fcntl.flock(f, fcntl.LOCK_EX)
|
fcntl.flock(f, fcntl.LOCK_EX)
|
||||||
# If the output file is empty, then it means that `websocket.php` read it. Anyway we don't wait it and we append what we want to output.
|
# If the output file is empty, then it means that `websocket.php` read it. Anyway we don't wait it and we append what we want to output.
|
||||||
@ -26,7 +26,6 @@ def write(s):
|
|||||||
f.write(s)
|
f.write(s)
|
||||||
f.flush()
|
f.flush()
|
||||||
fcntl.flock(f, fcntl.LOCK_UN)
|
fcntl.flock(f, fcntl.LOCK_UN)
|
||||||
f.close()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.exit(e)
|
sys.exit(e)
|
||||||
|
|
||||||
@ -69,8 +68,8 @@ for fileIndex, file in enumerate(files):
|
|||||||
write(toWrite)
|
write(toWrite)
|
||||||
break
|
break
|
||||||
|
|
||||||
f = open(clientFilePath)
|
with open(clientFilePath) as f:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
fcntl.flock(f, fcntl.LOCK_EX)
|
fcntl.flock(f, fcntl.LOCK_EX)
|
||||||
if f.read() == '':
|
if f.read() == '':
|
||||||
@ -81,5 +80,3 @@ while True:
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.exit(e)
|
sys.exit(e)
|
||||||
|
|
||||||
f.close()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user