Skip to content

Don't strip ANSI from stdout (fixes #2365)#2366

Merged
basfroman merged 4 commits intoopentensor:stagingfrom
vaqxai:patch-1
Nov 22, 2024
Merged

Don't strip ANSI from stdout (fixes #2365)#2366
basfroman merged 4 commits intoopentensor:stagingfrom
vaqxai:patch-1

Conversation

@vaqxai
Copy link
Contributor

@vaqxai vaqxai commented Oct 21, 2024

  • Until now ANSI was stripped from stdout if bittensor was not running within a TTY (like in PM2) by colorama when it was intialized
  • This caused colored output to be broken under PM2 (and other process managers which do not give a TTY do bittensor/python
  • Bittensor posseses its own file logger, which makes this behavior unnecessary and unwanted.
  • This patch disables that behavior.

Where ANSI Stripping takes place in colorama: https://github.com/tartley/colorama/blob/136808718af8b9583cb2eed1756ed6972eda4975/colorama/ansitowin32.py#L102

Bittensor call to colorama which indirectly breaks colors in terminal output in PM2:

init(autoreset=True)

Fix for issue #2365

- Until now ANSI was stripped from stdout if bittensor was not running within a TTY (like in PM2)
- This caused colored output to be broken under PM2 (and other process managers which do not give a TTY do bittensor/python
- Bittensor posseses its own file logger, which makes this behavior unnecessary and unwanted.
- This patch disables that behavior.
@vaqxai
Copy link
Contributor Author

vaqxai commented Oct 21, 2024

I found out that using strip=False introduces arbitrary newlines, instead, wrap=False can be used, and everything works correctly.

Maybe this should be user-definable by some config parameter?

Only without output wrapping does terminal output under PM2 behave correctly.
@thewhaleking
Copy link
Contributor

Sorry, what is PM2?

@thewhaleking
Copy link
Contributor

No response from OP after two weeks. Closing. Can be re-opened if still needed.

@thewhaleking thewhaleking reopened this Nov 22, 2024
@thewhaleking thewhaleking changed the base branch from master to staging November 22, 2024 17:26
Copy link
Collaborator

@basfroman basfroman left a comment

Choose a reason for hiding this comment

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

I tested this. Works well for me.

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.

ANSI Escape Sequences do not work under PM2 in version of bittensor older than 6.9.4

3 participants