473,785 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

httplib, threading, wx app freezing after 4 hours

The program displays images from a motion jpeg webcam.
(Motion jpeg is a bastardization of multi-part mime.)
<http://wp.netscape.com/assist/net_sites/pushpull.html>

It runs perfectly for about 4 hours, then freezes.
I'm stuck. How do I debug this?

(Using: Python 2.4.3, wxPython 2.6.3.2, Windows 2000 and XP)

There are no tracebacks, the gui continues to run,
isAlive() and activeCount() indicate that the thread is OK,
"print I'm alive" stops. CPU % usage is 0

I figure it is hanging in r.readline() or f.read()

Can anyone suggest techniques to help me learn what is going on.

I'm using httplib.HTTP instead of httplib.HTTPCon nection because
I don't find that HTTPConnection has readline().
Mark Rainess
=============== =============== =============== ============
class mjpeg_get(threa ding.Thread):
def run(self):
while 1:
while 1:
# print I'm connecting
h = httplib.HTTP(se lf.url)
h.putrequest('G ET','VIDEO.CGI' )
h.putheader('Ac cept','text/html')
h.endheaders()
if errcode == 200:
f = h.getfile()
break
# cleanup and try again

s = cStringIO()
while 1:
# print I'm alive
try:
# do f.readline() to get headers
# get count from 'Content-length:'
s.reset()
s.write(f.read( count))
s.truncate()
wx.CallAfter(se lf.window.onUpd ateImg, s)
continue
except:
# print error
# cleanup and try again
break

class Frame(wx.Frame) :
def OnIdle(self, event):
# for debugging display result of
# Thread.isAlive( )
# threading.activ eCount()
if self.gotImage is True:
# do display self.sImage
self.gotImage = False
def onUpdateImg(sel f, parm):
if self.gotImage is False:
self.sImage.res et()
self.sImage.wri te(parm.getvalu e())
self.sImage.tru ncate()
self.sImage.res et()
self.gotImage = True
=============== =============== =============== ============
Jul 22 '06 #1
3 1937
Mark,

httplib will block waiting for a server connection. I am not sure if
that is your problem but you could try a quick and dirty workaround of
recording a timestamp of the last data transfer and then have a timer
in a separate thread and if too much time passed, restart the retrieval
thread and issue a warning. Also check the memory on your machine in
case some buffer fills the memory up and the machine gets stuck.
To understand what's really happening try to debug the program. Try
Winpdb debugger you can find it here:
http://www.digitalpeers.com/pythondebugger/
Nick Vatamaniuc

Mark rainess wrote:
The program displays images from a motion jpeg webcam.
(Motion jpeg is a bastardization of multi-part mime.)
<http://wp.netscape.com/assist/net_sites/pushpull.html>

It runs perfectly for about 4 hours, then freezes.
I'm stuck. How do I debug this?

(Using: Python 2.4.3, wxPython 2.6.3.2, Windows 2000 and XP)

There are no tracebacks, the gui continues to run,
isAlive() and activeCount() indicate that the thread is OK,
"print I'm alive" stops. CPU % usage is 0

I figure it is hanging in r.readline() or f.read()

Can anyone suggest techniques to help me learn what is going on.

I'm using httplib.HTTP instead of httplib.HTTPCon nection because
I don't find that HTTPConnection has readline().
Mark Rainess
=============== =============== =============== ============
class mjpeg_get(threa ding.Thread):
def run(self):
while 1:
while 1:
# print I'm connecting
h = httplib.HTTP(se lf.url)
h.putrequest('G ET','VIDEO.CGI' )
h.putheader('Ac cept','text/html')
h.endheaders()
if errcode == 200:
f = h.getfile()
break
# cleanup and try again

s = cStringIO()
while 1:
# print I'm alive
try:
# do f.readline() to get headers
# get count from 'Content-length:'
s.reset()
s.write(f.read( count))
s.truncate()
wx.CallAfter(se lf.window.onUpd ateImg, s)
continue
except:
# print error
# cleanup and try again
break

class Frame(wx.Frame) :
def OnIdle(self, event):
# for debugging display result of
# Thread.isAlive( )
# threading.activ eCount()
if self.gotImage is True:
# do display self.sImage
self.gotImage = False
def onUpdateImg(sel f, parm):
if self.gotImage is False:
self.sImage.res et()
self.sImage.wri te(parm.getvalu e())
self.sImage.tru ncate()
self.sImage.res et()
self.gotImage = True
=============== =============== =============== ============
Jul 22 '06 #2

Mark rainess wrote:
[...]
It runs perfectly for about 4 hours, then freezes.
I'm stuck. How do I debug this?
[...]
Can anyone suggest techniques to help me learn what is going on.
By inspection: "errcode" is undefined; I expect you stripped the
example
a bit too far. If it is set to something other 200, it looks like you
loop out.

You are calling wx.CallAfter() from a different thread than runs the
GUI.
Is that documented to be safe? I've read that wxPostEvent() is is the
call to
use for this.

Next thing to try is adding enough logging to tell exactly what
statement
hangs.
--
--Bryan

Jul 23 '06 #3
br************* **********@yaho o.com wrote:
Mark rainess wrote:
[...]
>It runs perfectly for about 4 hours, then freezes.
I'm stuck. How do I debug this?
[...]
>Can anyone suggest techniques to help me learn what is going on.

By inspection: "errcode" is undefined; I expect you stripped the
example
a bit too far. If it is set to something other 200, it looks like you
loop out.

You are calling wx.CallAfter() from a different thread than runs the
GUI.
Is that documented to be safe? I've read that wxPostEvent() is is the
call to
use for this.

Next thing to try is adding enough logging to tell exactly what
statement
hangs.

Thanks guys, I found the problem.

I had screen-saver set to None and power set to blank monitor after 30
minutes. The problem occurred after the monitor blanked. I remembered I
re-flashed my bios a few weeks ago. I didn't check the bios
power-management settings. I'm not going to reboot now to check because
I have too much stuff open.

I set power to never blank monitor. Now there is no problem.

I added code to monitor for activity and to kill and restart the thread
if activity stops. Now if power-management kills it, it wakes-up when
the screen returns.

I think using wx.CallAfter() the way I have is correct. I will check
that. It does work properly though.

Mark
Jul 23 '06 #4

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

Similar topics

1
2882
by: Brian Beck | last post by:
Hi. I'm having some problems with code based directly on the following httplib documentation code: http://www.zvon.org/other/python/doc21/lib/httplib-examples.html I've included the code and traceback at the end of this post. The odd thing is, using DEPRECATED FUNCTIONS to perform the same function works fine!
0
1916
by: Leon | last post by:
I use sniffer look,it's status is 200,but run getresponse() can occur error ResponseNotReady I try wait it by 5 seconds,but still occur error ResponseNotReady source code.... import httplib,threading def waitSeconds(): sResponse = httpClient.getresponse() print sResponse.reason
0
2934
by: Robert | last post by:
did you solve this problem? It seems to be still present here with py2.3.5. Robert -- From: Manish Jethani <manish.j@gmx.net> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en
3
5609
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan dueTime) is always set to 6 days, 23 hours, 59 minutes, .. Some weeks ?!?, the timer restarts immediately after its execution (and loop indefinitely). I have made a lot of tests and this issue does not occur with a delay < 1 day .. Any suggestion
8
8217
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd party COM component that takes about 5 seconds to run one of its functions (Network IO bound call). Since I dont want my GUI to freeze
13
1815
by: John | last post by:
I've got some reasonably complex business logic in my C# code, in a class called by a ASP.NET page. This takes around 3-4 seconds to execute. It's not dependent on SQL calls or anything like that. I know of the problems with the worker process doing two things at once from the main thread pool (The old "Sit in a tight loop for 20 seconds and watch all your webapps die!" issue). So I've worked around the issue by spawning the business...
5
1534
by: OpticTygre | last post by:
Heheh...I've got lots of questions today. If I have a loop that calls the same subroutine several times (that subroutine may be processor and network intensive): For i = 1 to 100 Call mySub(IPAddress(i)) Next And inside mySub, I'm initializing a new network connection (SFTP if you
4
2321
by: Patrick Altman | last post by:
I am attempting to use a HEAD request against Amazon S3 to check whether a file exists or not and if it does parse the md5 hash from the ETag in the response to verify the contents of the file so as to save on bandwidth of uploading files when it is not necessary. If the file exist, the HEAD works as expected and I get valid headers back that I can parse and pull the ETag out of the dictionary using getheader('ETag') (using the slice to...
3
4073
by: rhXX | last post by:
hi all, i'm using this tutorial example import httplib h = httplib.HTTP("www.python.org") h.putrequest('GET','/index.html') h.putheader('User-Agent','Lame Tutorial Code') h.putheader('Accept','text/html')
0
10324
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
10090
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
9949
tracyyun
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...
0
8971
agi2029
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...
0
6739
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();...
0
5380
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
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
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.