473,854 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython and thread memory problems?


I took an example from wxPython with the IE web browser and
created a refresh button to automatically refresh a web page in 5
second intervals. But I notice that the memory utilization in Python
keeps increasing over time. Can anyone tell me why this is happening?
Here is my code:

=============== =============== =============== =============== =============== =

import wx, re
import time, thread
from urlparse import *

if wx.Platform == '__WXMSW__':
import wx.lib.iewin as iewin

refresh = 0


class TestPanel(wx.Pa nel):
def __init__(self, parent, frame=None):
wx.Panel.__init __(
self, parent, -1,
style = wx.TAB_TRAVERSA L |

self.current = "http://www.google.com"
self.frame = frame

if frame:
self.titleBase = frame.GetTitle( )

sizer = wx.BoxSizer(wx. VERTICAL)
btnSizer = wx.BoxSizer(wx. HORIZONTAL)

self.ie = iewin.IEHtmlWin dow(self, -1, style =

btn = wx.Button(self, -1, "Open", style=wx.BU_EXA CTFIT)
self.Bind(wx.EV T_BUTTON, self.OnOpenButt on, btn)
btnSizer.Add(bt n, 0, wx.EXPAND|wx.AL L, 2)

btn = wx.Button(self, -1, "Home", style=wx.BU_EXA CTFIT)
self.Bind(wx.EV T_BUTTON, self.OnHomeButt on, btn)
btnSizer.Add(bt n, 0, wx.EXPAND|wx.AL L, 2)

btn = wx.Button(self, -1, "<--", style=wx.BU_EXA CTFIT)
self.Bind(wx.EV T_BUTTON, self.OnPrevPage Button, btn)
btnSizer.Add(bt n, 0, wx.EXPAND|wx.AL L, 2)

btn = wx.Button(self, -1, "-->", style=wx.BU_EXA CTFIT)
self.Bind(wx.EV T_BUTTON, self.OnNextPage Button, btn)
btnSizer.Add(bt n, 0, wx.EXPAND|wx.AL L, 2)

btn = wx.Button(self, -1, "Stop", style=wx.BU_EXA CTFIT)
self.Bind(wx.EV T_BUTTON, self.OnStopButt on, btn)
btnSizer.Add(bt n, 0, wx.EXPAND|wx.AL L, 2)

btn = wx.Button(self, -1, "Search", style=wx.BU_EXA CTFIT)
self.Bind(wx.EV T_BUTTON, self.OnSearchPa geButton, btn)
btnSizer.Add(bt n, 0, wx.EXPAND|wx.AL L, 2)

btn = wx.Button(self, -1, "Refresh", style=wx.BU_EXA CTFIT)
self.Bind(wx.EV T_BUTTON, self.OnRefreshP ageButton, btn)
btnSizer.Add(bt n, 0, wx.EXPAND|wx.AL L, 2)

btn = wx.Button(self, -1, "AutoRefres h", style=wx.BU_EXA CTFIT)
self.Bind(wx.EV T_BUTTON, self.OnAutoRefr eshPageButton, btn)
btnSizer.Add(bt n, 0, wx.EXPAND|wx.AL L, 2)

txt = wx.StaticText(s elf, -1, "Location:" )
btnSizer.Add(tx t, 0, wx.CENTER|wx.AL L, 2)

self.location = wx.TextCtrl(sel f, -1, "",

self.location.B ind(wx.EVT_CHAR , self.OnLocation Return)
btnSizer.Add(se lf.location, 1, wx.EXPAND|wx.AL L, 2)

sizer.Add(btnSi zer, 0, wx.EXPAND)
sizer.Add(self. ie, 1, wx.EXPAND)

self.ie.LoadUrl (self.current)

self.SetSizer(s izer)
# Since this is a wxWindow we have to call Layout ourselves
self.Bind(wx.EV T_SIZE, self.OnSize)

# Hook up the event handlers for the IE window
self.Bind(iewin .EVT_DocumentCo mplete, self.OnDocument Complete,

thread.start_ne w_thread(self.r efresh_url, (5,))

def OnSize(self, evt):

def OnLocationRetur n(self, evt):
if evt.KeyCode() == wx.WXK_RETURN:
self.ie.Navigat e(self.location .GetValue(),
iewin.NAV_NoRea dFromCache | iewin.NAV_NoWri teToCache)

def OnOpenButton(se lf, event):
dlg = wx.TextEntryDia log(self, "Open Location",
"Enter a full URL or local path",
self.current, wx.OK|wx.CANCEL )
dlg.CentreOnPar ent()

if dlg.ShowModal() == wx.ID_OK:
self.current = dlg.GetValue()
self.ie.Navigat e(self.current,
iewin.NAV_NoRea dFromCache | iewin.NAV_NoWri teToCache)


def OnHomeButton(se lf, event):
self.ie.GoHome( ) ## ET Phone Home!

def OnPrevPageButto n(self, event):
self.ie.GoBack( )

def OnNextPageButto n(self, event):
self.ie.GoForwa rd()

def OnStopButton(se lf, evt):

def OnSearchPageBut ton(self, evt):
self.ie.GoSearc h()

def OnRefreshPageBu tton(self, evt):
self.ie.Refresh Page(iewin.REFR ESH_COMPLETELY)

def OnAutoRefreshPa geButton(self, evt):
global refresh
refresh = not refresh

def refresh_url(sel f, delay):
global refresh
while (1):
time.sleep(dela y)
if refresh:
self.ie.Navigat e(self.ie._get_ LocationURL(),
iewin.NAV_NoRea dFromCache |
iewin.NAV_NoWri teToCache)

def OnDocumentCompl ete(self, evt):
self.current = evt.URL
self.location.S etValue(self.cu rrent)

class Frame(wx.Frame) :
def __init__(self, parent=None, id=-1, title='Title',
pos=wx.DefaultP osition, size=(640, 480)):
wx.Frame.__init __(self, parent, id, title, pos, size)

self.attr = {}
self.attr['panel'] = TestPanel(self)

class App(wx.App):
def OnInit(self):
self.attr = {}

self.attr['frame'] = Frame(title='My Window')
self.SetTopWind ow(self.attr['frame'])

return True

def main():
app = App()

if __name__ == '__main__':

Jul 18 '05 #1
0 1381

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: ulysses | last post by:
hi, I'm working in python 5 months. I think it's very cool language. I do a p2p python program GUI. First I make a software by wxpython. But I find wxpython use many many memory. Second I use PYQT. But memory use still big. But but but when I minimize the windows to taskbar, a fantasy something happened. memory use very very low when windows minimize.
by: James Goldwater | last post by:
I'm starting a new hopfully-commercial project soon, and I face a dilemma about whether Python with wxPython would be appropriate. The project has 3 main areas: a) manipulation of lists and trees, using.. b) a hopefully dead-sexy gui, all in order to... c) eventually pump out certain bits of the datastructure over the network in semi-realtime (< 10ms accuracy or so).
by: Zunbeltz Izaola | last post by:
Hi, I have the following problem. I'm developing a GUI program (wxPython). This program has to comunicate (TCP) whit other program that controls a laboratory machine to do a measurement. I have a dialog box, wiht two buttoms "Start measurement" and "Stop". "Start" executes a function that do the measurement in the following way.
by: Glurt Wuntal | last post by:
I am a newbie with Python. It's a great language, but I would like to be able to present a simple gui menu for some of my scripts; something better than using 'raw_input' prompts. Any recommendations for a program that will allow me to create the gui screens? Something useable in Linux. thanks.
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame. But the "app.MainLoop()" in wxpython looks like conflicting with the "while 1:" in socket server. After I commented the "app.MainLoop()", everything is working except two things: 1. if I click anywhere on the screen with the mouse, the image is...
by: Patrick Smith | last post by:
Hi, I'm hoping someone here will be able to help as I've been struggling with this problem for a few days now. I'm working on an application that is creating a ProgressDialog, and then creating a thread that runs a function from another module in the program. The problem is, when the cancel button on the ProgressDialog is pressed, the thread that was created continues to run. How can I make it so that when the cancel button on the...
by: Shafik | last post by:
Hello folks, I'm having an issue with mixing wxPython and threading ... I realize multi-threading always introduces subtle bugs, but the following scenario is just odd: I start a dummy thread, that does nothing but increment a counter and print its value to the screen, then afterwards, I start the wxPython application. I get nothing but weird behavior: sometimes the gui just crashes, sometimes I get an exception, sometimes it runs for...
by: bullockbefriending bard | last post by:
I am a complete ignoramus and newbie when it comes to designing and coding networked clients (or servers for that matter). I have a copy of Goerzen (Foundations of Python Network Programming) and once pointed in the best direction should be able to follow my nose and get things sorted... but I am not quite sure which is the best path to take and would be grateful for advice from networking gurus. I am writing a program to display horse...
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread in particular, but I am curious to know why some people find it "ugly" or "bad" or whatever. It has its own bugs and missing features, of course, but it is one of the major GUI player in the arena, together with PyQt and PyGTK.
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.