Remove unused imports and avoid bare exceptions

This commit is contained in:
cclauss 2019-03-28 05:09:06 +01:00 committed by GitHub
parent 9a5e0ee19c
commit 4ce58239e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,13 +2,12 @@ import errno
import os
import psutil
import stat
import sys
import time
from . import NamedEvent
from unittest.mock import patch
from pathlib import PosixPath
def _isfifo_strict(path):
# https://github.com/giampaolo/psutil/blob/release-5.4.6/psutil/_common.py#L362
try:
@ -20,6 +19,7 @@ def _isfifo_strict(path):
else:
return stat.S_ISFIFO(st.st_mode)
class PosixNamedEvent(NamedEvent):
"""
A wrapper for named events using a FIFO (named pipe)
@ -49,7 +49,7 @@ class PosixNamedEvent(NamedEvent):
try:
with patch("psutil._psplatform.isfile_strict", _isfifo_strict):
return PosixNamedEvent.__has_open_file_handles_real(path)
except:
except Exception:
# Something happened(tm), or the platform doesn't uses isfile_strict (ex: BSD).
# Do a best effort.
return PosixNamedEvent.__has_open_file_handles_real(path)
@ -68,7 +68,7 @@ class PosixNamedEvent(NamedEvent):
os.mkfifo(p)
self.__path = p
self.__fifo = os.open(p, os.O_NONBLOCK) # Keep a handle to the FIFO for exists() to detect us
self.__fifo = os.open(p, os.O_NONBLOCK) # Keep a handle to the FIFO so exists() detects us
self.__fifo_in = None
self.__fifo_out = None
self.__name = name