I want to start a simple HTTP-Server from a GUI (wxPython) with the module multiprocessing.
This code works fine if I start it directly with Python. But in the built version (with PyInstaller 2 or 3) the GUI starts again if I start the multiprogress -> not the code in the run-function, the whole application. Has anybody an idea why?
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import wx, sys, time, thread, datetime, os, platform, multiprocessing, socket
import favicon
from genLicense import load as loadLicense
from licenseDetailDialog import Dialog as licenseDetailDialog
class mp(multiprocessing.Process):
    def __init__(self, queue, func, *args):
        multiprocessing.Process.__init__(self)
        self.queue = queue
        self.func = func
        self.args = args
    def run(self):
        time.sleep(0.1)
        try:
            self.func(*self.args)
        except Exception as e:
            self.queue.put(e)
            print(e)
class MainFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER
        wx.Frame.__init__(self, *args, **kwds)
        # [...]
        self.button_startstop = wx.Button(self, wx.ID_ANY, _("Server &starten"))
        # [...]
    def startstop(self, event):
        if self.running:
            self._stop()
        else:
            self._start()
    def _start(self):
        print("Starting...")
        try:
            port = 123
            queue = multiprocessing.Queue()
            self.server_process = mp(queue, ACC_main.START, port)
            self.server_process.start()
            print("\tPID: {}\n\n{}".format(self.server_process.pid, "="*50))
            # [...]
            self.running = True
        except:
            # [...]
    def _stop(self):
        print("\n{}\nStopping...".format("="*50))
        if self.running:
            print("\tPID: {}\n".format(self.server_process.pid))
            self.server_process.terminate()
        self.running = False
                Add the line multiprocessing.freeze_support() to your code before creating your window. It's documented here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With