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

BlockingIOError: [Errno 11] write could not complete without blocking thrown in full screen app with style

Open
#864 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

Seen with:

  • python 3.6.7
  • prompt_toolkit 2.0.9
  • aionursery 0.3.0
  • asyncio

I have a non-standard architecture, where:

  • asyncio loop is run in a separate App class
  • main app runs async clients in a nursery:
        async with Nursery() as ns:
            ns.start_soon(self.pull_sink())
            /.../
            ns.start_soon(gui(self, self.loop, self.test_queue))

gui is an async function where I create prompt toolkit application.
I call use_asyncio_event_loop with the loop passed from the parent app.
To launch prompt toolkit app I use another nursery context (I will need more concurrent tasks here):

    async with Nursery() as ns:
        ns.start_soon(application.run_async())
        /.../

where application is prompt toolkit app.
In the layout I have TextArea widget, which I initialize with a style for bg and fg colors.
When I create prompt toolkit app as full screen it fails:

    Traceback (most recent call last):
      File "/usr/lib/python3.6/asyncio/tasks.py", line 537, in _wrap_awaitable
        return (yield from awaitable.__await__())
      File "/home/wojtek/.local/lib/python3.6/site-packages/prompt_toolkit/eventloop/coroutine.py", line 90, in step_next
        new_f = coroutine.throw(exc)
      File "/home/wojtek/.local/lib/python3.6/site-packages/prompt_toolkit/application/application.py", line 658, in _run_async2
        result = yield f
      File "/home/wojtek/.local/lib/python3.6/site-packages/prompt_toolkit/eventloop/coroutine.py", line 86, in step_next
        new_f = coroutine.send(None)
      File "/home/wojtek/.local/lib/python3.6/site-packages/prompt_toolkit/application/application.py", line 601, in _run_async
        self._redraw()
      File "/home/wojtek/.local/lib/python3.6/site-packages/prompt_toolkit/application/application.py", line 444, in _redraw
        self.renderer.render(self, self.layout)
      File "/home/wojtek/.local/lib/python3.6/site-packages/prompt_toolkit/renderer.py", line 595, in render
        output.flush()
      File "/home/wojtek/.local/lib/python3.6/site-packages/prompt_toolkit/output/vt100.py", line 601, in flush
        out.write(data.encode(self.stdout.encoding or 'utf-8', 'replace'))
    BlockingIOError: [Errno 11] write could not complete without blocking

Interestingly, when I set full_screen setting to False there is no exception thrown, the style is applied to the widget, and the app is running as expected.
Also, if I do not apply the style to the widget the app runs fine in full screen mode.
Since this is a non-standard usage I tried pulling different string by myself to see if maybe I am doing something wrong that is not mentioned in the docs, but without success.
Do you maybe have a hint whether my approach has a bug somewhere or, less likely, prompt toolkit needs a fix?
Thank you.

EDIT: Another twist - this error appears only when I launch my python program from within midnight commander. It does not appear within xterm.

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

Reproduce the failure with Python 3.6.7, prompt_toolkit 2.0.9, asyncio, full_screen enabled, and the styled TextArea, comparing xterm with midnight commander. Start at prompt_toolkit/application/application.py, renderer.py, and output/vt100.py around the redraw and flush traceback. Done means determining whether the terminal environment or the non-standard event-loop setup causes the BlockingIOError, and documenting or fixing the confirmed cause.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.