Skip to content

Commit

Permalink
add a way to hide runtime warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotduarte committed Jun 13, 2024
1 parent 5a030b0 commit 85cb64a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
26 changes: 15 additions & 11 deletions cx_Freeze/hooks/multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ def load_multiprocessing(finder: ModuleFinder, module: Module) -> None:
BaseContext.freeze_support = lambda self: _spawn_freeze_support()
DefaultContext.freeze_support = lambda self: _spawn_freeze_support()
if _spawn_is_forking(sys.argv):
main_module = sys.modules["__main__"]
main_spec = main_module.__spec__
main_code = main_spec.loader.get_code(main_spec.name)
if "freeze_support" not in main_code.co_names:
print('''
import BUILD_CONSTANTS
if not getattr(BUILD_CONSTANTS, "ignore_freeze_support_message", 0):
main_module = sys.modules["__main__"]
main_spec = main_module.__spec__
main_code = main_spec.loader.get_code(main_spec.name)
if "freeze_support" not in main_code.co_names:
print('''
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
Expand All @@ -64,14 +66,16 @@ def load_multiprocessing(finder: ModuleFinder, module: Module) -> None:
freeze_support()
...
To fix this issue, refer to the documentation:\n \
To fix this issue, or to hide this message, refer to the documentation:
\
https://cx-freeze.readthedocs.io/en/stable/faq.html#multiprocessing-support
''', file=sys.stderr)
#import os, signal
#os.kill(os.getppid(), signal.SIGHUP)
#sys.exit(os.EX_SOFTWARE)
_spawn_freeze_support()
del main_module, main_spec, main_code
#import os, signal
#os.kill(os.getppid(), signal.SIGHUP)
#sys.exit(os.EX_SOFTWARE)
del main_module, main_spec, main_code
del BUILD_CONSTANTS
_spawn_freeze_support()
# cx_Freeze patch end
"""
code_string = module.file.read_text(encoding="utf_8") + dedent(source)
Expand Down
8 changes: 8 additions & 0 deletions doc/src/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ In addition, if the module is being run normally by the Python interpreter on
any OS (the program has not been frozen), then `freeze_support()` has no
effect.

To hide the runtime warning message, on Linux and macOS, specify in the
:ref:`cx_freeze_build_exe` command, the :option:`constants` option with the
value 'ignore_freeze_support_message=1'. For example, using the command line:

.. code-block:: console
cxfreeze --script test.py build_exe --constants='ignore_freeze_support_message=1'
.. note::

Contrary to what the Python docs may state, you MUST use
Expand Down

0 comments on commit 85cb64a

Please sign in to comment.