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 for running in pythonw #2448

Merged
merged 11 commits into from Jun 19, 2022
Merged

Fix for running in pythonw #2448

merged 11 commits into from Jun 19, 2022

Conversation

timmo001
Copy link
Contributor

@timmo001 timmo001 commented May 4, 2022

Running sanic server on windows and on pythonw.exe causes the app to silently crash due to sys.stdout being None.

NVIDIA_Share_2022-05-04_12-36-03

This adds a check for stdout. The rest of the server then continues to function normally.

@codecov
Copy link

codecov bot commented May 7, 2022

Codecov Report

Merging #2448 (db3238f) into main (d1c5e80) will increase coverage by 0.002%.
The diff coverage is 85.714%.

@@              Coverage Diff              @@
##              main     #2448       +/-   ##
=============================================
+ Coverage   87.267%   87.269%   +0.002%     
=============================================
  Files           60        60               
  Lines         5097      5098        +1     
  Branches       913       913               
=============================================
+ Hits          4448      4449        +1     
  Misses         476       476               
  Partials       173       173               
Impacted Files Coverage Δ
sanic/mixins/runner.py 95.726% <66.666%> (-0.019%) ⬇️
sanic/application/logo.py 100.000% <100.000%> (ø)
sanic/application/motd.py 95.454% <100.000%> (ø)
sanic/log.py 100.000% <100.000%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1c5e80...db3238f. Read the comment docs.

sanic/mixins/runner.py Outdated Show resolved Hide resolved
@ahopkins
Copy link
Member

@timmo001 I am sorry, in my head I was looking at the original logic thinking that it was wrong. That is why I suggested the change. But, it was correct. I reverted the PR back to your original suggestion. Let's pretend I never suggested that to begin with 😆

Thanks for catching this for us.

Copy link
Member

@ahopkins ahopkins left a comment

Choose a reason for hiding this comment

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

Here's a suggestion that ACTUALLY makes sense...

There are a few more places that follow a similar pattern. Perhaps you can add the same change:

sanic/mixins/runner.py:427:        if sys.stdout and sys.stdout.isatty() and not self.state.is_debug:
sanic/mixins/runner.py:618:                if sys.stdout.isatty():
sanic/mixins/runner.py:659:                        if sys.stdout.isatty():
sanic/log.py:86:    if sys.stdout.isatty():
sanic/application/motd.py:39:        motd_class = MOTDTTY if sys.stdout.isatty() else MOTDBasic
sanic/application/logo.py:47:        if sys.stdout.isatty()

Maybe we can add a function into ./compat.py:

def is_atty():
    return sys.stdout and sys.stdout.isatty()

@timmo001 timmo001 requested a review from ahopkins May 12, 2022 18:04
ahopkins
ahopkins previously approved these changes May 24, 2022
@timmo001
Copy link
Contributor Author

timmo001 commented Jun 1, 2022

Update on this? I see its been approved but the checks are failing.

@timmo001 timmo001 requested a review from ahopkins June 8, 2022 22:05
@timmo001
Copy link
Contributor Author

I've rebased, but this requires an approver to run

@timmo001
Copy link
Contributor Author

Fixed lint, needs approval

ahopkins
ahopkins previously approved these changes Jun 19, 2022
@ahopkins ahopkins merged commit 6c48c8b into sanic-org:main Jun 19, 2022
@timmo001 timmo001 deleted the patch-1 branch June 19, 2022 12:31
@timmo001
Copy link
Contributor Author

Schedule for the next release?

@ahopkins
Copy link
Member

Should be this week.

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.

None yet

2 participants