Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #71637 > unrolled thread
| Started by | chris@freeranger.com |
|---|---|
| First post | 2014-05-15 21:36 -0700 |
| Last post | 2014-05-16 06:41 +0000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
IndexError: pop from empty list chris@freeranger.com - 2014-05-15 21:36 -0700
Re: IndexError: pop from empty list Gary Herron <gary.herron@islandtraining.com> - 2014-05-15 21:48 -0700
Re: IndexError: pop from empty list chris@freeranger.com - 2014-05-15 22:08 -0700
Re: IndexError: pop from empty list Peter Otten <__peter__@web.de> - 2014-05-16 10:15 +0200
Re: IndexError: pop from empty list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-16 06:41 +0000
| From | chris@freeranger.com |
|---|---|
| Date | 2014-05-15 21:36 -0700 |
| Subject | IndexError: pop from empty list |
| Message-ID | <960b2711-6ed5-4a31-845b-7d15e39c9cf2@googlegroups.com> |
Any ideas about what this might mean?
Running Debian Wheezy on a RaspBerry Pi and collecting data on a dispatch thread that is reading input on the serial port (connected to xbee series 1).
It happens every few days but it really chokes the program.
Thanks for any tips,
ChrisJ
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 95, in run
self._callback(self.wait_read_frame())
File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 400, in wait_read_frame
return self._split_response(frame.data)
File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 288, in _split_response
info[parse_rule[0]] = parse_rule[1](self, info)
File "/usr/local/lib/python2.7/dist-packages/xbee/ieee.py", line 117, in <lambda>
lambda xbee,original: xbee._parse_samples(original['samples'])
File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 357, in _parse_samples
digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0))
IndexError: pop from empty list
[toc] | [next] | [standalone]
| From | Gary Herron <gary.herron@islandtraining.com> |
|---|---|
| Date | 2014-05-15 21:48 -0700 |
| Message-ID | <mailman.10056.1400215690.18130.python-list@python.org> |
| In reply to | #71637 |
On 05/15/2014 09:36 PM, chris@freeranger.com wrote: > Any ideas about what this might mean? > > Running Debian Wheezy on a RaspBerry Pi and collecting data on a dispatch thread that is reading input on the serial port (connected to xbee series 1). > > It happens every few days but it really chokes the program. > > Thanks for any tips, > ChrisJ > > > > > Exception in thread Thread-2: > Traceback (most recent call last): > File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner > self.run() > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 95, in run > self._callback(self.wait_read_frame()) > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 400, in wait_read_frame > return self._split_response(frame.data) > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 288, in _split_response > info[parse_rule[0]] = parse_rule[1](self, info) > File "/usr/local/lib/python2.7/dist-packages/xbee/ieee.py", line 117, in <lambda> > lambda xbee,original: xbee._parse_samples(original['samples']) > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 357, in _parse_samples > digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0)) > IndexError: pop from empty list The error means that sample_bytes is an empty list so calling pop is an error. Or were you asking something deeper, like *why* sample_bytes is an empty list? Gary Herron
[toc] | [prev] | [next] | [standalone]
| From | chris@freeranger.com |
|---|---|
| Date | 2014-05-15 22:08 -0700 |
| Message-ID | <5aa8abd1-05d4-4cf3-99fc-08493306b6a1@googlegroups.com> |
| In reply to | #71638 |
No, that was pretty much what I was looking for. If anyone has an answer to the deeper question, that would be icing on the cake. What is interesting is that usually the traceback shows the line of code that I invoke which, deep inside a library I'm using, has generated an error. In this case I don't know which of my commands has spawned the error. I can experiment, I suppose, with putting a try/catch around suspected lines of code... Thanks, Chris. On Thursday, May 15, 2014 9:48:00 PM UTC-7, Gary Herron wrote: > On 05/15/2014 09:36 PM, chris@freeranger.com wrote: > > > Any ideas about what this might mean? > > > > > > Running Debian Wheezy on a RaspBerry Pi and collecting data on a dispatch thread that is reading input on the serial port (connected to xbee series 1). > > > > > > It happens every few days but it really chokes the program. > > > > > > Thanks for any tips, > > > ChrisJ > > > > > > > > > > > > > > > Exception in thread Thread-2: > > > Traceback (most recent call last): > > > File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner > > > self.run() > > > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 95, in run > > > self._callback(self.wait_read_frame()) > > > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 400, in wait_read_frame > > > return self._split_response(frame.data) > > > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 288, in _split_response > > > info[parse_rule[0]] = parse_rule[1](self, info) > > > File "/usr/local/lib/python2.7/dist-packages/xbee/ieee.py", line 117, in <lambda> > > > lambda xbee,original: xbee._parse_samples(original['samples']) > > > File "/usr/local/lib/python2.7/dist-packages/xbee/base.py", line 357, in _parse_samples > > > digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0)) > > > IndexError: pop from empty list > > > > The error means that sample_bytes is an empty list so calling pop is an > > error. > > > > Or were you asking something deeper, like *why* sample_bytes is an > > empty list? > > > > Gary Herron
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-05-16 10:15 +0200 |
| Message-ID | <mailman.10062.1400228133.18130.python-list@python.org> |
| In reply to | #71640 |
chris@freeranger.com wrote:
> No, that was pretty much what I was looking for. If anyone has an answer
> to the deeper question, that would be icing on the cake.
>
> What is interesting is that usually the traceback shows the line of code
> that I invoke which, deep inside a library I'm using, has generated an
> error. In this case I don't know which of my commands has spawned the
> error.
>
> I can experiment, I suppose, with putting a try/catch around suspected
> lines of code...
It looks like the xbee library is responsible for reading the right amount
of bytes and then fails to parse them properly.
So it is possible (even likely I think) that you have run into a bug in the
library.
A report to the author/maintainer should be in order. Of course it would
help if you can find a way to reproduce the error. One way to do that is to
modify the code
def _parse_samples(self, io_bytes):
try:
... # original code of the method
except IndexError:
# replace path with something that makes sense on your system
with open("/path/to/io_bytes.data", "wb") as f:
f.write(io_bytes)
raise
wait until the error occurs again and then send the contents of the
io_bytes.data file along with your bug report.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-05-16 06:41 +0000 |
| Message-ID | <5375b312$0$29977$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #71637 |
On Thu, 15 May 2014 21:36:49 -0700, chris wrote:
> Any ideas about what this might mean?
[jumping ahead]
> digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0))
> IndexError: pop from empty list
sample_bytes is an empty list. Or it could be a list with just a single
sample. You try to pop from it twice in a row, so unless it contains at
least two items, one or the other of the pops will fail.
Without understanding the context, it's impossible to say what the best
way to fix this, but my guess is that you need to guard this clause with
something that ensures that there are at least two samples, and if not,
just waits until there are. E.g.:
if len(sample_bytes) >= 2:
digital_data_set = (sample_bytes.pop(0) << 8 | sample_bytes.pop(0))
or similar. This assumes the function will try again a moment later,
after it's had a chance to gather some more data from the serial port.
Ultimately, that's the problem: you're trying to process data faster than
in can be collected.
--
Steven D'Aprano
http://import-that.dreamwidth.org/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web