title: cx freeze and multiprocessing.map_async spawning main thread instead of function
body: <p>I have an multiprocess GUI application that works flawlessly when invoked using python on Mac. <br>
  For spawning my processes, and running the function <code>func</code> asynchronously, I'm using <code>multiprocessing.pools</code>:</p>
  <pre class="lang-py prettyprint-override"><code>def worker(self): 
          calulation_promise = self._pool.map_async(func, (self.simulated_values), 
                          callback=self.simFin, error_callback=self.simError)
          return calulation_promise
  </code></pre>
  <p>Now, I need to make an executable from my project using <em>cx-freeze</em>. I'm using the documentation's template provided <a href="https://cx-freeze.readthedocs.io/en/latest/setup_script.html#" rel="nofollow noreferrer">here</a>.</p>
  <pre class="lang-py prettyprint-override"><code>import sys
  from cx_Freeze import setup, Executable
  
  # Dependencies are automatically detected, but it might need fine tuning.
  # &quot;packages&quot;: [&quot;os&quot;] is used as example only
  excludes = [&quot;Pyside2.Qt5WebEngineCore.dll&quot;, &quot;PySide6&quot;]
  build_exe_options = {&quot;packages&quot;: ['multiprocessing'], &quot;excludes&quot;: excludes}
  
  
  # base=&quot;Win32GUI&quot; should be used only for Windows GUI app
  base = None
  if sys.platform == &quot;win32&quot;:
      base = &quot;Win32GUI&quot;
  
  setup(
      name = &quot;guifoo&quot;,
      version = &quot;0.1&quot;,
      description = &quot;My GUI application!&quot;,
      options = {&quot;build_exe&quot;: build_exe_options},
      executables = [Executable(&quot;main.py&quot;, base=base)]
  )
  </code></pre>
  <p>Unfortunately, when my main application calls my <code>worker ()</code> function, it always starts the main process (which starts a new MainWindow GUI).
  That means, instead of executing the function <code>func</code>, it somehow starts the main thread over and over again (see the outputs for more clarity)</p>
  <h1>Working example:</h1>
  <p><em>Note:</em> This is a working example to reproduce the issue.</p>
  <pre class="lang-py prettyprint-override"><code>import sys, os, time, logging, platform, multiprocessing, random
  from multiprocessing import Process, Pool, cpu_count, freeze_support
  from PySide2.QtWidgets import (QLineEdit, QPushButton, QApplication, QVBoxLayout, QDialog)
  from PySide2.QtCore import Signal, QObject
  from rich.logging import RichHandler
  
  class Form(QDialog):
  
      def __init__(self, parent=None):
          super(Form, self).__init__(parent)
          logging.info (&quot;Stared gui...&quot;)
          # Create widgets
          self.edit = QLineEdit(&quot;&lt;empty&gt;&quot;)
          self.button = QPushButton(&quot;Start worker&quot;)
          # Create layout and add widgets
          layout = QVBoxLayout()
          layout.addWidget(self.edit)
          layout.addWidget(self.button)
          self.setLayout(layout)                          # Set dialog layout
          self.button.clicked.connect(self.startWorker)   # Add button signal to greetings slot
  
      # Greets the user
      def startWorker(self):
          logging.info(&quot;Stared worker...&quot;)
          tw = ThreadWrapper()
          self.promise = tw.worker()
          tw.signals.finished.connect(self.finished)
      
      def finished(self):
          self.edit.setText(str(self.promise.get()))
  
  class ThreadWrapper():
      def __init__(self):
          self.simulated_values = range(1, 30, 1)
          self._pool = Pool(processes=8)
          self.signals = WorkerSignals()
  
      def simFin(self, value):
          logging.info(&quot;%s&quot; % (value))
          self.signals.finished.emit()
      
      def simError(self, value):
          logging.error(&quot;%s&quot; % (value))
  
      def worker(self):
          
          calulation_promise = self._pool.map_async(func, (self.simulated_values), 
                          callback=self.simFin, error_callback=self.simError)
          return calulation_promise
  
  
  class WorkerSignals(QObject):
      finished = Signal()
  
  # A function which needs an arbitrary amount of time to finish
  def func(value):
      wait = random.randint(1, 5); time.sleep(wait) 
      res = value**value
      print(&quot;THREAD: %d*%d = %d; waiting %d&quot; % (value, value, res, wait))
      return res
  
  def main():
      logging.basicConfig(level=&quot;DEBUG&quot;, format=&quot;%(name)s | %(message)s&quot;, datefmt=&quot;[%X]&quot;, handlers=[RichHandler()])
      if platform.system() == &quot;Darwin&quot;:
              multiprocessing.set_start_method('spawn')
              os.environ['QT_MAC_WANTS_LAYER'] = '1'
              os.environ['QT_MAC_USE_NSWINDOW'] = '1'
              
      app = QApplication(sys.argv)
      window = Form()
      window.show()  
      sys.exit(app.exec_())
  
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>
  <h1>Outputs</h1>
  <h2>Using python</h2>
  <pre><code>[20:41:50] INFO     root | Stared gui...                             _main.py:11
  [20:41:52] INFO     root | Stared worker...                          _main.py:24
  THREAD: 3*3 = 27; waiting 1
  THREAD: 4*4 = 256; waiting 3
  THREAD: 1*1 = 1; waiting 5
  THREAD: 2*2 = 4; waiting 5
  [20:41:57] INFO     root | [1, 4, 27, 256]   
  </code></pre>
  <h2>Using the executable</h2>
  <pre><code>[20:44:03] INFO     root | Stared gui...                             _main.py:11
  [20:44:05] INFO     root | Stared worker...                          _main.py:24
  [20:44:06] INFO     root | Stared gui...                             _main.py:11
  [20:44:06] INFO     root | Stared gui...                             _main.py:11
  [20:44:06] INFO     root | Stared gui...                             _main.py:11
  [20:44:06] INFO     root | Stared gui...                             _main.py:11
  [20:44:06] INFO     root | Stared gui...                             _main.py:11
  [20:44:06] INFO     root | Stared gui...                             _main.py:11
  [20:44:06] INFO     root | Stared gui...                             _main.py:11
  [20:44:06] INFO     root | Stared gui...                             _main.py:11
  [20:44:06] INFO     root | Stared gui...                             _main.py:11
  </code></pre>
  <h1>Additional Details:</h1>
  <ul>
  <li>Mac OS Big Sur, Ver. 11.5.1</li>
  <li>Python 3.7.4</li>
  <li>PySide2, ver 5.15.2</li>
  </ul>