prompt-toolkit / prompt-toolkit/python-prompt-toolkit

RuntimeErrors are emitted from generator_to_async_generator

Open
#833 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

Apologies, as I haven't really fully figured out how to reproduce this -- other than to say that I am pretty sure it's only started happening "recently".

When I use ptpython, RuntimeErrors are often spit out as I enter lines. E.g.:

⊙  venv/bin/ptpython                                                                                                                                                                                                                                                           Julian@home
>>> import json

>>>
>>>
>>>
>>>
>>> iException RuntimeError: RuntimeError('cannot release un-acquired lock',) in finalizer of <generator object generator_to_async_generator at 0x0000000106c76778> ignored
>>> import
>>>

(Additional runtime errors will continue to be emitted as I continue to use the REPL. And I can reproduce even in a fresh venv that contains only ptpython).

generator_to_async_generator is an object that appears to be defined here, which is why I filed this here, under the assumption that it's that object that has some sort of bug where it's trying to release locks it hasn't acquired, but of course it's possible that the issue is in how ptpython is using it.

The only other thing likely worth mentioning is that this is PyPy, so it's possible that there's some code assuming that finalizers run immediately (which isn't the case on interpreters other than CPython), but yeah I'm obviously completely guessing at things, and wanted to file this just to capture it, and in case what's happening was obvious to the maintainers.

$ venv/bin/pip freeze
⊙  venv/bin/pip freeze                                                                                                                                                                                                                                                         Julian@home
cffi==1.11.5
docopt==0.6.2
greenlet==0.4.13
jedi==0.13.2
parso==0.3.3
prompt-toolkit==2.0.8
ptpython==2.0.4
Pygments==2.3.1
readline==6.2.4.1
six==1.12.0
wcwidth==0.1.7

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating generator_to_async_generator in the prompt-toolkit code and reproducing the reported finalizer error in a PyPy ptpython environment with the listed versions. Trace how ptpython invokes it and how the lock behaves during generator finalization. Done means the cause is isolated and the RuntimeError no longer appears during REPL use, with a regression test if the project has a suitable test location.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.