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

Fix cli blockingioerror #11934

Closed
wants to merge 5 commits into from
Closed

Conversation

trammell
Copy link
Contributor

Proposed changes:

Add print_blocking() and try/except block to manage blocking print errors in CLI.

Fixes https://rasa-open-source.atlassian.net/browse/OSS-183

Status (please check what you already did):

  • added some tests for the functionality
  • updated the documentation
  • updated the changelog (please check changelog for instructions)
  • reformat files using black (please check Readme for instructions)

@trammell trammell requested a review from a team as a code owner January 13, 2023 20:48
@trammell trammell requested review from znat and removed request for a team January 13, 2023 20:48
rasa/shared/utils/cli.py Show resolved Hide resolved
rasa/shared/utils/cli.py Show resolved Hide resolved
@trammell trammell requested a review from a team as a code owner February 26, 2023 15:22
@m-vdb m-vdb requested review from ancalita and removed request for znat February 27, 2023 09:40
Copy link
Member

@ancalita ancalita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the initiative to fix this 💯
To double-check, the ticket description referred to 2.x minor series, is this occurring in 3.x too?

try:
print(output)
except BlockingIOError:
print_blocking(output)


def print_success(*args: Any) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we need a docstring here because the linter checks for any issues in the same module where the changes are being made (even if unrelated with the code changes). And we can't merge without making the linter happy 😅

import sys
from typing import Any, Text, NoReturn

import rasa.shared.utils.io


def print_blocking(string) -> None:
"""Save fcntl settings and restore them after print()."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unfamiliar with fcntl, could we expand the docstring a bit more about the need for this.

def print_blocking(string) -> None:
"""Save fcntl settings and restore them after print()."""
save = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL)
new = save & ~os.O_NONBLOCK
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we add some comment above this line to explain what it's doing concisely.

import sys
from typing import Any, Text, NoReturn

import rasa.shared.utils.io


def print_blocking(string) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a unit test for this new function?

@ancalita
Copy link
Member

@trammell One more thing about fcntl, it seems this doesn't work on Windows, so we'll need to find a different solution for this OS...or a different cross-platform solution altogether.

@trammell
Copy link
Contributor Author

@ancalita that is a very good point. I'm going to retract this PR and implement the changes discussed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants