Helper to ensure file descriptors opened in _get_handles are closed
(self)
| 1378 | |
| 1379 | @contextlib.contextmanager |
| 1380 | def _on_error_fd_closer(self): |
| 1381 | """Helper to ensure file descriptors opened in _get_handles are closed""" |
| 1382 | to_close = [] |
| 1383 | try: |
| 1384 | yield to_close |
| 1385 | except: |
| 1386 | if hasattr(self, '_devnull'): |
| 1387 | to_close.append(self._devnull) |
| 1388 | del self._devnull |
| 1389 | for fd in to_close: |
| 1390 | try: |
| 1391 | if _mswindows and isinstance(fd, Handle): |
| 1392 | fd.Close() |
| 1393 | else: |
| 1394 | os.close(fd) |
| 1395 | except OSError: |
| 1396 | pass |
| 1397 | raise |
| 1398 | |
| 1399 | if _mswindows: |
| 1400 | # |
no test coverage detected