high cpu usage in wxPython with Twisted

Lonnie Princehouse finite.automaton at gmail.com
Tue Jul 20 20:22:57 CEST 2004


Try profiling your program with hotshot.  At least it should tell you
which functions are sucking up resources.


marchew <darek at tiger.com.pl> wrote in message news:<mailman.629.1090315050.5135.python-list at python.org>...
> hi,
> 
>   i have a problem integrating wxPython and Twisted under Win32. my
>   application consumes 40-50% of CPU resources when wxFrame is visible and reactor
>   (twisted) is running. i looked at integration example which comes with twisted
>   package and figured that it also has that problem. here comes listing:
> 
>   PYTHON_HOME\Lib\site-packages\TwistedDocs\examples\wxdemo.py
> 
> #----------------------------------------------------------------
> from wxPython.wx import *
> 
> from twisted.internet import wxreactor
> wxreactor.install()
> from twisted.internet import reactor
> 
> 
> # set up so that "hello, world" is printed once a second
> def helloWorld():
>     print "hello, world"
>     reactor.callLater(1, helloWorld)
> reactor.callLater(1, helloWorld)
> 
> def twoSecondsPassed():
>     print "two seconds passed"
> 
> reactor.callLater(2, twoSecondsPassed)
> 
> ID_EXIT  = 101
> 
> class MyFrame(wxFrame):
>     def __init__(self, parent, ID, title):
>         wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, wxSize(300, 200))
>         menu = wxMenu()
>         menu.Append(ID_EXIT, "E&xit", "Terminate the program")
>         menuBar = wxMenuBar()
>         menuBar.Append(menu, "&File");
>         self.SetMenuBar(menuBar)
>         EVT_MENU(self, ID_EXIT,  self.DoExit)
> 
>     def DoExit(self, event):
>         self.Close(true)
>         reactor.stop()
>         
> class MyApp(wxApp):
> 
>     def OnInit(self):
>         frame = MyFrame(NULL, -1, "Hello, world")
>         frame.Show(true)
>         self.SetTopWindow(frame)
>         return true
> 
> 
> def demo():
>     app = MyApp(0)
>     reactor.registerWxApp(app)
>     reactor.run(0)
> 
> 
> if __name__ == '__main__':
>     demo()
> #----------------------------------------------------------------
> 
>   can You help me? has anyone encountered similar problem?
>     
> --  
>  marchew     mailto:darek at tiger.com.pl



More information about the Python-list mailing list