X Tutup
Skip to content

Commit eb7ba12

Browse files
committed
switched to subprocess Popen for better debugging
1 parent 4f12ee2 commit eb7ba12

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

find_active_server.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
sys.exit(4)
8585

8686
__author__ = 'Hari Sekhon'
87-
__version__ = '0.5'
87+
__version__ = '0.6'
8888

8989

9090
class FindActiveServer(CLI):
@@ -267,15 +267,26 @@ def check_ping(host, count=None, wait=None):
267267
raise UnknownError("passed invalid wait '{0}' to check_ping method, must be a valid integer!"\
268268
.format(wait))
269269
log.info("pinging host '%s' (count=%s, wait=%s)", host, count, wait)
270-
ping_count = '-c {0}'.format(count)
270+
count_switch = '-c'
271271
if platform.system().lower() == 'windows':
272-
ping_count = '-n {0}'.format(wait)
273-
ping_wait = '-w {0}'.format(wait)
272+
count_switch = '-n'
273+
wait_switch = '-w'
274274
if platform.system().lower() == 'darwin':
275-
ping_wait = '-W {0}'.format(wait)
275+
wait_switch = '-W'
276+
# causes hang if count / wait are not cast to string
277+
cmd = ['ping', count_switch, '{0}'.format(count), wait_switch, '{0}'.format(wait), host]
278+
log.debug('cmd: %s', ' '.join(cmd))
279+
#log.debug('args: %s', cmd)
276280
try:
277-
exitcode = subprocess.call(["ping", ping_count, ping_wait, host],
278-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
281+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
282+
#log.debug('communicating')
283+
(stdout, stderr) = process.communicate()
284+
#log.debug('waiting for child process')
285+
process.wait()
286+
exitcode = process.returncode
287+
log.debug('stdout: %s', stdout)
288+
log.debug('stderr: %s', stderr)
289+
log.debug('exitcode: %s', exitcode)
279290
if exitcode == 0:
280291
log.info("host '%s' responded to ping", host)
281292
return host

0 commit comments

Comments
 (0)
X Tutup