diff --git a/src/calibre/ebooks/oeb/polish/tests/base.py b/src/calibre/ebooks/oeb/polish/tests/base.py index dd78065d52..fcc21004a4 100644 --- a/src/calibre/ebooks/oeb/polish/tests/base.py +++ b/src/calibre/ebooks/oeb/polish/tests/base.py @@ -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')) diff --git a/src/calibre/scraper/simple.py b/src/calibre/scraper/simple.py index 8dcb423901..fdbf8a5af1 100644 --- a/src/calibre/scraper/simple.py +++ b/src/calibre/scraper/simple.py @@ -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() diff --git a/src/calibre/utils/lock.py b/src/calibre/utils/lock.py index c9ee5fb608..ab301018b2 100644 --- a/src/calibre/utils/lock.py +++ b/src/calibre/utils/lock.py @@ -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) - retry_for_a_time( - timeout, sleep_time, fcntl.flock, unix_retry, - f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB - ) + 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 diff --git a/src/calibre/utils/test_lock.py b/src/calibre/utils/test_lock.py index 22968baf2d..411ac63adf 100644 --- a/src/calibre/utils/test_lock.py +++ b/src/calibre/utils/test_lock.py @@ -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)