473,725 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython and thread memory problems?

Hi,

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 |
wx.CLIP_CHILDRE N |
wx.NO_FULL_REPA INT_ON_RESIZE
)

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 =
wx.NO_FULL_REPA INT_ON_RESIZE)

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, "",
style=wx.TE_PRO CESS_ENTER)

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,
self.ie)

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

def OnSize(self, evt):
self.Layout()

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)
else:
evt.Skip()

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)

dlg.Destroy()

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):
self.ie.Stop()

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.attr['frame'].Show()
self.SetTopWind ow(self.attr['frame'])

return True

def main():
app = App()
app.MainLoop()

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

Jul 18 '05 #1
0 1376

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

Similar topics

4
5018
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.
25
2616
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).
6
2934
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.
22
5048
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.
9
5555
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...
8
1683
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...
3
1610
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...
12
2176
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...
16
2410
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.
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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,...
0
9401
Oralloy
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...
1
9174
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,...
0
4517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
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.