Skip to content

[BUG] rich.print("[bright_blue uu]" + message) crashes with NotImplementedError #2645

Closed
@eblis

Description

@eblis

Describe the bug

I'm trying to do a print statement on Windows environment using rich and I get an exception.

rich.print("[bright_blue uu]" + message)

Provide a minimal code example that demonstrates the issue if you can. If the issue is visual in nature, consider posting a screenshot.

Windows 10 x64
Faust streaming application.
I'm using the terminal emulated by PyCharm.

From what I can tell the error is in console.py, around here:

                            try:
                                use_legacy_windows_render = (
                                    self.file.fileno() in _STD_STREAMS_OUTPUT
                                )
                            except (ValueError, io.UnsupportedOperation):
                                pass

image

The error doesn't appear in the main application, it appears in a library that uses rich.
If I write the same console message from my main application, before the library does it then it works ok.
But if the library wants to write the message it fails with the exception mentioned above.

Activity

eblis

eblis commented on Nov 15, 2022

@eblis
Author

I think the code should also ignore NotImplementedError as well:

                            except (ValueError, io.UnsupportedOperation, NotImplementedError):
                                pass

Changing the console.py code to this allows the messages to be written to console.

willmcgugan

willmcgugan commented on Nov 15, 2022

@willmcgugan
Member

That would certainly fix it, although fileno should not raise a NotImplementedError. You might want to raise this with the library that is supplying the file-like object.

eblis

eblis commented on Nov 15, 2022

@eblis
Author

In my main application the self.file member is initialized to this:
image

But later, in my library, it's (re?)initialized to this:
image

I didn't initialize it to this value, it was probably Faust (or I don't know who) who modified the file object.
I'm initializing a rich console like this:

        self.rich_console = rich.console.Console(color_system="256", force_terminal=True, file=None, quiet=quiet)

And then writing the message like so:

self.rich_console.print("[bright_blue uu]" + message)

Edit: I thought I had sent this with the other replies a while back, but looks like it was a draft, I sent it now just so we have all the details.

github-actions

github-actions commented on Nov 30, 2022

@github-actions

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @eblis@willmcgugan

      Issue actions

        [BUG] rich.print("[bright_blue uu]" + message) crashes with NotImplementedError · Issue #2645 · Textualize/rich