question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ready queue mutation, IndexError: pop from an empty deque

See original GitHub issue

Hey,

First, thanks for sharing the patch and publishing this library. I’m trying to workaround re-entrancy while converting a codebase incrementally to asyncio, where there are call chains of async > loop.run_until_complete(async).

I’ve hit an issue with the patch with handles from the _ready queue seemingly being popped from elsewhere. I.e. from python3.6/asyncio/base_events.py popping from the ready queue throws, because it iterates too far.

        ntodo = len(self._ready)
        for i in range(ntodo):
            handle = self._ready.popleft() # throws.
            if handle._cancelled:
                continue

The full exception stack trace looks like this:

return aio_batcher.run_until_complete(aio_batcher.evaluate_coroutines(json_data))
  File "/Users/cory/src/nd/util/aio_batcher/decorators.py", line 50, in run_until_complete
    return loop.run_until_complete(awaitable)
  File "/var/lib/conda/envs/nextdoor3/lib/python3.6/site-packages/nest_asyncio.py", line 63, in run_until_complete
    return self._run_until_complete_orig(future)
  File "/var/lib/conda/envs/nextdoor3/lib/python3.6/asyncio/base_events.py", line 454, in run_until_complete
    self.run_forever()
  File "/var/lib/conda/envs/nextdoor3/lib/python3.6/asyncio/base_events.py", line 421, in run_forever
    self._run_once()
  File "/var/lib/conda/envs/nextdoor3/lib/python3.6/asyncio/base_events.py", line 1411, in _run_once
    handle = self._ready.popleft()
IndexError: pop from an empty deque

My hypothesis is that one of the enqueued items triggers the nest_async, or else an enqueued item is processing other elements from the queue.

It is the worst kind of problem where it is reproducible, but I have yet to isolate a simple test case to make it easy to understand. Do you have a hunch of what might be happening? Perhaps something you ran into while writing the patch?

Thanks for your help, Cory

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
erdewitcommented, Aug 3, 2019

The repo has been updated to follow Cory’s approach of always using the patched loop. It also patches run_forever now instead of run_until_complete and with this it can stay closer to the base asyncio code.

I believe this should fix the issues, if it doesn’t let me know. I’ll keep this bug open for a while and when it works okay a 1.1 version will be released.

0reactions
ostrukcommented, Aug 19, 2019

Happy to help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

iostream's write :IndexError: pop from an empty deque
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group. To unsubscribe from this group and stop...
Read more >
Python while loop popleft() - ERROR: Empty deque
The code above executes all three commands and on the gamma command returns an "IndexError: pop from an empty deque." I understand why...
Read more >
insync@groups.io | IndexError: pop from an empty deque
In principal, my code works. However, after some run time, the 'pop from an empty queue' error occurs. Here is a traceback that...
Read more >
Changelog — Python 3.5.9 documentation
bpo-30301: Fix AttributeError when using SimpleQueue.empty() under spawn ... Now an IndexError will be raised when attempting to insert into a full deque....
Read more >
Changelog — documentation Python 3.7.0a0
bpo-30301: Fix AttributeError when using SimpleQueue.empty() under spawn and ... method when unpickle collections.deque and other list-like objects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found