high cpu usage in wxPython with Twisted

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • marchew

    #1

    high cpu usage in wxPython with Twisted

    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\Twiste dDocs\examples\ wxdemo.py

    #----------------------------------------------------------------
    from wxPython.wx import *

    from twisted.interne t import wxreactor
    wxreactor.insta ll()
    from twisted.interne t import reactor


    # set up so that "hello, world" is printed once a second
    def helloWorld():
    print "hello, world"
    reactor.callLat er(1, helloWorld)
    reactor.callLat er(1, helloWorld)

    def twoSecondsPasse d():
    print "two seconds passed"

    reactor.callLat er(2, twoSecondsPasse d)

    ID_EXIT = 101

    class MyFrame(wxFrame ):
    def __init__(self, parent, ID, title):
    wxFrame.__init_ _(self, parent, ID, title, wxDefaultPositi on, 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.SetTopWind ow(frame)
    return true


    def demo():
    app = MyApp(0)
    reactor.registe rWxApp(app)
    reactor.run(0)


    if __name__ == '__main__':
    demo()
    #----------------------------------------------------------------

    can You help me? has anyone encountered similar problem?

    --
    marchew mailto:darek@ti ger.com.pl
    --

    _______________ _______________ _______________ __
    Python-win32 mailing list
    Python-win32@python.or g


  • Lonnie Princehouse

    #2
    Re: high cpu usage in wxPython with Twisted

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


    marchew <darek@tiger.co m.pl> wrote in message news:<mailman.6 29.1090315050.5 135.python-list@python.org >...[color=blue]
    > 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\Twiste dDocs\examples\ wxdemo.py
    >
    > #----------------------------------------------------------------
    > from wxPython.wx import *
    >
    > from twisted.interne t import wxreactor
    > wxreactor.insta ll()
    > from twisted.interne t import reactor
    >
    >
    > # set up so that "hello, world" is printed once a second
    > def helloWorld():
    > print "hello, world"
    > reactor.callLat er(1, helloWorld)
    > reactor.callLat er(1, helloWorld)
    >
    > def twoSecondsPasse d():
    > print "two seconds passed"
    >
    > reactor.callLat er(2, twoSecondsPasse d)
    >
    > ID_EXIT = 101
    >
    > class MyFrame(wxFrame ):
    > def __init__(self, parent, ID, title):
    > wxFrame.__init_ _(self, parent, ID, title, wxDefaultPositi on, 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.SetTopWind ow(frame)
    > return true
    >
    >
    > def demo():
    > app = MyApp(0)
    > reactor.registe rWxApp(app)
    > reactor.run(0)
    >
    >
    > if __name__ == '__main__':
    > demo()
    > #----------------------------------------------------------------
    >
    > can You help me? has anyone encountered similar problem?
    >
    > --
    > marchew mailto:darek@ti ger.com.pl[/color]

    Comment

    Working...