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:
parent
47dc1b5b92
commit
b487126bb8
2 changed files with 16 additions and 0 deletions
|
|
@ -108,6 +108,19 @@ class Loop:
|
|||
(not os.minor(info.st_rdev) == minor)):
|
||||
raise UnexpectedDevice(minor, info.st_rdev, info.st_mode)
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
"""Close this loop device.
|
||||
|
||||
No operations on this object are valid after this call.
|
||||
"""
|
||||
if self.fd >= 0:
|
||||
os.close(self.fd)
|
||||
self.fd = -1
|
||||
self.devname = "<closed>"
|
||||
|
||||
def set_fd(self, fd):
|
||||
"""Bind a file descriptor to the loopback device
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue