Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eblis opened this issue Nov 15, 2022 · 4 comments · Fixed by #2678
Closed

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

eblis opened this issue Nov 15, 2022 · 4 comments · Fixed by #2678

Comments

@eblis
Copy link

eblis commented Nov 15, 2022

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.

@eblis
Copy link
Author

eblis commented Nov 15, 2022

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
Copy link
Collaborator

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
Copy link
Author

eblis commented Nov 15, 2022

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
Copy link

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants