Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34189 > unrolled thread

Re: Puzzling error msg.

Started byChris Angelico <rosuav@gmail.com>
First post2012-12-04 07:33 +1100
Last post2012-12-04 07:33 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Puzzling error msg. Chris Angelico <rosuav@gmail.com> - 2012-12-04 07:33 +1100

#34189 — Re: Puzzling error msg.

FromChris Angelico <rosuav@gmail.com>
Date2012-12-04 07:33 +1100
SubjectRe: Puzzling error msg.
Message-ID<mailman.440.1354566815.29569.python-list@python.org>
On Tue, Dec 4, 2012 at 4:37 AM,  <wrw@mac.com> wrote:
> Traceback (most recent call last):
>   File "./Connection_Monitor.py", line 146, in <module>
>     Google_up, Google_summary, Google_RTT, Google_stddev = Google.connection_test()
>   File "/Users/wrw/Dev/Python/Connection_Monitor/Version2.2/WorkingCopy/network.py", line 101, in connection_test
>     #
> IndexError: list index out of range
>
>
> The routine is pasted in below:
>
>     def connection_test(self):
>         self.network_up = True
>         self.error = None
>         ping_result = subprocess.Popen(['ping', '-qc6', self.target_IP], stderr = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0]
>         found_0 = '0 packets received' in ping_result
>         found_1 = '1 packets received' in ping_result
>         if found_0 == True or found_1 == True:
>             self.network_up = False
>             self.ping_summary = 'No route to host'
>             self.ping_RTT = 'NA'
>             self.ping_stddev = 'NA'
>             return self.network_up, self.ping_summary, self.ping_RTT, self.ping_stddev
> #

Is that the end of the function? What does it return if neither
found_0 nor found_1? If that's the end, the function will be returning
None (as all functions do on "flowing off the end"), but that would
give a quite different error (namely, 'NoneType' is not iterable, at
the unpacking).

Is it possible that the error actually came from further up (with a
faulty line number) and was actually because communicate() somehow
returned an empty list? That's the only place in the code quoted that
I'm seeing indexing, but communicate() is supposed to return a tuple,
not a list.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web