Skip to content

Nicegui and multiprocessing calculation #4353

Answered by rodja
chupins asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for pointing out this discrepancy @chupins. This is super crucial and quite fundamental when using NiceGUI with multiprocessing. If you add a print statement inside the main guard (where you init nicegui) you will see that it is called for every subprocess. This is due to the fact that each process is starting a fresh Python interpreter — which means it re-imports the main module. A standard main guard with __name__ == '__main__' protects code from being run in such spawned sub-processes. But with NiceGUI the default is auto-reload (eg. ui.run(reload=True)). This means the main process __main__ already starts the code in a sub-process which then identifies as __name__ == '__mp_mai…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@chupins
Comment options

Answer selected by chupins
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@falkoschindler
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants