mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
More immediate resource closures
This commit is contained in:
parent
5fc243a93d
commit
a48a0fc52f
@ -86,7 +86,8 @@ def get_split_book(fmt='epub'):
|
||||
src = os.path.join(os.path.dirname(__file__), 'split.html')
|
||||
if needs_recompile(ans, src):
|
||||
x = src.replace('split.html', 'index.html')
|
||||
raw = open(src, 'rb').read().decode('utf-8')
|
||||
with open(src, 'rb') as sf:
|
||||
raw = sf.read().decode('utf-8')
|
||||
try:
|
||||
with open(x, 'wb') as f:
|
||||
f.write(raw.encode('utf-8'))
|
||||
|
@ -97,6 +97,8 @@ class Overseer:
|
||||
for w in self.workers.values():
|
||||
w.stdin.write(b'EXIT:0\n')
|
||||
w.stdin.flush()
|
||||
w.stdin.close()
|
||||
w.stdout.close()
|
||||
for w in self.workers.values():
|
||||
if self.safe_wait(w, 0.2) is None:
|
||||
w.terminate()
|
||||
|
@ -87,10 +87,14 @@ def lock_file(path, timeout=15, sleep_time=0.2):
|
||||
timeout, sleep_time, windows_open, windows_retry, path
|
||||
)
|
||||
f = unix_open(path)
|
||||
try:
|
||||
retry_for_a_time(
|
||||
timeout, sleep_time, fcntl.flock, unix_retry,
|
||||
f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB
|
||||
)
|
||||
except Exception:
|
||||
f.close()
|
||||
raise
|
||||
return f
|
||||
|
||||
|
||||
|
@ -109,6 +109,7 @@ class IPCLockTest(unittest.TestCase):
|
||||
finally:
|
||||
if child.poll() is None:
|
||||
child.kill()
|
||||
child.wait()
|
||||
|
||||
def test_exclusive_file_other_process_clean(self):
|
||||
self.run_other_ef_op(True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user