From 10e5548513353ba976ab030a9b2084db3eba9224 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 6 Apr 2017 10:51:14 -0500 Subject: [PATCH] pingnet: Fix ResourceWarning --- pingnet.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pingnet.py b/pingnet.py index 4d381f7..4340560 100755 --- a/pingnet.py +++ b/pingnet.py @@ -64,10 +64,11 @@ class Pinger(threading.Thread): break def ping(self, host): - p = subprocess.Popen(['ping', '-c', '1', '-W', '1', host], - stdin=open(os.devnull), - stdout=open(os.devnull, 'w'), - stderr=subprocess.STDOUT) + with open(os.devnull, 'r+') as nul: + p = subprocess.Popen(['ping', '-c', '1', '-W', '1', host], + stdin=nul, + stdout=nul, + stderr=subprocess.STDOUT) p.wait() if p.returncode == 0: if not self.quiet: