Зачем выходить из моего wx.Process с этими странными кодами выхода.(2 считается) - PullRequest
0 голосов
/ 26 сентября 2019

Я не знаю, почему мой скрипт Python завершает работу с этим кодом выхода.

Что-то не так, если процесс завершает работу, в том числе основной файл exitst, с редкими кодами выхода, такими как
Процесс завершен с кодом выхода -1073741510 (0xC000013A: прерван Ctrl + C
[Я знаю, что не нажимал Ctrl + C (я использовал Windows 10 и PyCharm IDE, а в PyCharm вы не можете нажать Ctrl+ C для завершения сценария)]

или
Процесс завершен с кодом выхода -1073741819 (0xC0000005)
Что-то странное происходит с этим кодом. Это похоже на pythonСам сбой.

Основной файл

    def start(self):
        from time import sleep
        from os.path import exists
        from lib import utils
        import os, sys
        # fp = "temp/QplayBubbles-" + self.version + '.zip'
        _dir = utils.replace_ver2dir(self.version)
        if not exists("versions/%s" % _dir):
            self.download()

        if not os.path.exists("mods/%s" % _dir):
            os.makedirs("mods/%s" % _dir)

        print("Starting Version: %s" % _dir)
        cfg = {"version": self.version,
               "versionDir": _dir,
               "build": self.dir_data[_dir]
               }

        print("Current Directory: %s" % os.curdir)

        # if self.dir_data[_dir] < 16:
        #     self.root.destroy()

        if self.dir_data[_dir] >= 16:
            from lib.process import Process
            process = Process()
            process.Execute("python versions/"+_dir+"/__main__.py {version} {versionDir} {build}".format(_dir, **cfg))
        else:
            from lib.process import Process
            process = Process()
            process.Execute("python old_load.py {version} {versionDir} {build}".format(_dir, **cfg))

Модуль lib.process:

import wx
import threading


class Process(wx.App):
    def __init__(self):
        wx.App.__init__(self, True)

        # We can either derive from wx.Process and override OnTerminate
        # or we can let wx.Process send this window an event that is
        # caught in the normal way...
        self.Bind(wx.EVT_END_PROCESS, self.OnProcessEnded)

        self.process = None
        self.MainLoop()

    def OnExecuteBtn(self, cmd):

        self.process = wx.Process(self)
        self.process.Redirect()
        pid = wx.Execute(cmd, wx.EXEC_ASYNC, self.process)
        print('OnExecuteBtn: "%s" pid: %s\n' % (cmd, pid))
        #
        # self.inp.Enable(True)
        # self.sndBtn.Enable(True)
        # self.termBtn.Enable(True)
        # self.cmd.Enable(False)
        # self.exBtn.Enable(False)
        # self.inp.SetFocus()

    def Execute(self, command):
        self.OnExecuteBtn(command)
        print("Starting Process Update")
        threading.Thread(None, self.Update, "ProcessUpdate").start()

    def OnSendText(self, text):
        print('OnSendText: "%s"\n' % text)
        text += '\n'
        self.process.GetOutputStream().write(text.encode('utf-8'))

    def Send(self, text):
        self.OnSendText(text)

    def OnCloseStream(self):
        print('OnCloseStream\n')
        self.process.CloseOutput()

    def Close(self):
        self.OnCloseStream()

    def Update(self):
        while self.process is not None:
            self.OnIdle()

    def OnIdle(self):
        if self.process is not None:
            try:
                stream = self.process.GetInputStream()

                if stream.CanRead():
                    text = stream.read()
                    print("[Game]: "+text.decode()[:-1])
            except RuntimeError:
                pass

    def OnProcessEnded(self, evt):
        print('OnProcessEnded, pid:%s,  exitCode: %s\n' %
              (evt.GetPid(), evt.GetExitCode()))

        if evt.GetExitCode() == 1:
            pass
        else:
            self.process.Destroy()
        self.process = None

    def ShutdownDemo(self):
        # Called when the demo application is switching to a new sample. Tell
        # the process to close (by closign its output stream) and then wait
        # for the termination signals to be received and processed.
        if self.process is not None:
            self.process.CloseOutput()
            wx.MilliSleep(250)
            wx.Yield()
            self.process = None

Если кому-то понадобится больше кода, просто спросите.

...