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 examples for freeze_support() issue on windows #2741

Merged
merged 2 commits into from Jul 5, 2023

Conversation

deounix
Copy link
Contributor

@deounix deounix commented Apr 17, 2023

Sanic on windows should always run inside:

if __name__ == "__main__": app.run()

Check this: https://docs.python.org/2/library/multiprocessing.html#the-process-class

For an explanation of why (on Windows) the if __name__ == '__main__' part is necessary, see [Programming guidelines]

Without the __name__ == "__main__" it throw this error on windows:

RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

On Linux, Mac it's run normally.
I think we should update the docs to notify the users about this issue.

@deounix deounix requested a review from a team as a code owner April 17, 2023 04:26
Copy link
Member

@SaidBySolo SaidBySolo left a comment

Choose a reason for hiding this comment

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

Good catch

@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Patch coverage: 100.000% and project coverage change: +0.006 🎉

Comparison is base (af67801) 88.938% compared to head (1ce41b9) 88.944%.

Additional details and impacted files
@@              Coverage Diff              @@
##              main     #2741       +/-   ##
=============================================
+ Coverage   88.938%   88.944%   +0.006%     
=============================================
  Files           92        92               
  Lines         6952      6956        +4     
  Branches      1185      1185               
=============================================
+ Hits          6183      6187        +4     
  Misses         527       527               
  Partials       242       242               
Impacted Files Coverage Δ
sanic/application/logo.py 100.000% <100.000%> (ø)
sanic/application/motd.py 97.849% <100.000%> (ø)
sanic/asgi.py 91.729% <100.000%> (+0.062%) ⬆️
sanic/helpers.py 100.000% <100.000%> (ø)
sanic/log.py 100.000% <100.000%> (ø)
sanic/mixins/startup.py 92.753% <100.000%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ahopkins ahopkins merged commit f2cc83c into sanic-org:main Jul 5, 2023
32 checks passed
@deounix deounix deleted the freeze branch July 7, 2023 11:59
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

3 participants