Script takes a few seconds to close in terminal

Hello,

I’m reading Michael Driscoll’s “Creating GUI Applications with wxPython” to learn how to write scripts in Phoenixø.

I notice this script takes a few seconds to close in the DOS terminal window after I close the GUI:

#Python 3.12.0
#wxPython 4.2.1

import wx,sys

class MyPanel(wx.Panel):
  def __init__(self, parent):
    super().__init__(parent)

    self.Bind(wx.EVT_CHAR_HOOK, self.OnKeyUP)
    self.text = wx.TextCtrl ( self, value = "Line1\r\nLine2", style = wx.TE_READONLY | wx.TE_MULTILINE)    
    #How to "grey out" background to show text widget is read only?
    #BAD self.text.Disable()
    main_sizer = wx.BoxSizer(wx.HORIZONTAL)
    main_sizer.Add(self.text, proportion=1, flag=wx.ALL | wx.CENTER | wx.EXPAND, border=5)
    self.SetSizer(main_sizer)

  def OnKeyUP(self, event):
    keyCode = event.GetKeyCode()
    if keyCode == wx.WXK_ESCAPE:
        #NOTHING self.Close()
        sys.exit(0) 
    #event.Skip()       

class MyFrame(wx.Frame):
  def __init__(self):
    super().__init__(None, title='Banks')
    panel = MyPanel(self)
    self.Show()

if __name__ == '__main__':
  app = wx.App()
  frame = MyFrame()
  app.MainLoop()

FWIW, here’s what PyScripter IDE says:

*** Remote Interpreter Reinitialized ***
Traceback (most recent call last):
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\stream.py", line 214, in read
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 208, in __call__
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 76, in syncreq
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 471, in sync_request
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\async_.py", line 95, in value
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\async_.py", line 45, in wait
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 387, in serve
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\channel.py", line 50, in recv
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\stream.py", line 223, in read
EOFError: [WinError 10054] An existing connection was forcibly closed by the remote host
Traceback (most recent call last):
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 152, in __getattribute__
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 76, in syncreq
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 471, in sync_request
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 492, in async_request
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 477, in _async_request
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 259, in _send
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\channel.py", line 69, in send
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\stream.py", line 233, in write
  File "C:\PyScripter\Lib\rpyc.zip\rpyc\core\stream.py", line 81, in __getattr__
EOFError: stream has been closed
>>>
*** Remote Interpreter Reinitialized ***

Thank you.

ø BTW, is it the only book that covers wxW4 ? Are wikis etc. the only alternative?

I tested your code using Python 3.10.12 + wxPython 4.2.1 gtk3 (phoenix) wxWidgets 3.2.2.1 on Linux Mint 21.3 and the app closed immediately when I pressed the Esc key, so perhaps this is a Windows issue?

However, the usual approach would be to call self.GetParent().Destroy() rather than sys.exit(0).

well, the subject is Python 3.12.* :upside_down_face:

Thanks for the infos. After replacing this line, it’s slightly faster, but it still takes a couple of seconds. Maybe Python/wxP does some clean-up when a script ends.

Good point. Apologies for misreading.

You can also try wxGlade. This includes a tutorial that introduces wxGlade and wxPython at the same time…
wxGlade - Browse /wxglade/1.1.0 at SourceForge.net
Welcome to wxGlade’s documentation! — wxGlade 1.0.0 documentation

I hope you have found the wxPython demo. This is also one of the most valueable sources.
See here at the bottom: wxPython · PyPI
Or here Index of /wxPython4/extras/4.2.1

1 Like

well, the error on Windows

the return code of  'test.py'  is  -1073741819

Press any key to continue . . .

results with the simple Python script

import wx

so the bug I suppose must be in the wrapper

for me, PyScipter gives no error at all, just like IDLE, but Geany runs the import correctly and gives back the correct ERRORLEVEL -1073741819 :rofl:

well, I put that question to the Python Help and Barry Scott hinted precisely to an access violation which points, as far as I can judge, to the extension modules

wx._core._wxPyCleanup ? (better no Emoji today)

I’m not gonna be an ass, but $MYPROGRAM$
… sometimes … Said the same shit.

If 1:
main()

it’s always there and popped up exactly with change to Python 3.12
so one would say it’s Python (that’s why I listened there), but … :pleading_face:

Ok, I see some folks here are Grammer Nazis, but 0-1 have written their own code editor.

I thank all the comedians in the audience, as there are thousands of them, but only one of you.

have you tried antigravity lately?