loop: explicitly close fds to loop devices

Don't wait until python's garbage collector closes the file descriptors
to loop devices. Close them when the `LoopServer` context manager exits,
after an assembler has finished running.
This commit is contained in:
Lars Karlitski 2020-01-19 10:46:04 +01:00 committed by Tom Gundersen
parent 47dc1b5b92
commit b487126bb8
2 changed files with 16 additions and 0 deletions

View file

@ -70,6 +70,7 @@ class LoopServer:
try:
lo.set_fd(fd)
except OSError as e:
lo.close()
if e.errno == errno.EBUSY:
continue
raise e
@ -108,6 +109,8 @@ class LoopServer:
def __exit__(self, *args):
self.event_loop.call_soon_threadsafe(self.event_loop.stop)
self.thread.join()
for lo in self.devs:
lo.close()
class LoopClient: