By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,441 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,441 IT Pros & Developers. It's quick & easy.

httplib, threading, wx app freezing after 4 hours

P: n/a
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.HTTPConnection because
I don't find that HTTPConnection has readline().
Mark Rainess
================================================== =======
class mjpeg_get(threading.Thread):
def run(self):
while 1:
while 1:
# print I'm connecting
h = httplib.HTTP(self.url)
h.putrequest('GET','VIDEO.CGI')
h.putheader('Accept','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(self.window.onUpdateImg, 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.activeCount()
if self.gotImage is True:
# do display self.sImage
self.gotImage = False
def onUpdateImg(self, parm):
if self.gotImage is False:
self.sImage.reset()
self.sImage.write(parm.getvalue())
self.sImage.truncate()
self.sImage.reset()
self.gotImage = True
================================================== =======
Jul 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.HTTPConnection because
I don't find that HTTPConnection has readline().
Mark Rainess
================================================== =======
class mjpeg_get(threading.Thread):
def run(self):
while 1:
while 1:
# print I'm connecting
h = httplib.HTTP(self.url)
h.putrequest('GET','VIDEO.CGI')
h.putheader('Accept','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(self.window.onUpdateImg, 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.activeCount()
if self.gotImage is True:
# do display self.sImage
self.gotImage = False
def onUpdateImg(self, parm):
if self.gotImage is False:
self.sImage.reset()
self.sImage.write(parm.getvalue())
self.sImage.truncate()
self.sImage.reset()
self.gotImage = True
================================================== =======
Jul 22 '06 #2

P: n/a

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

P: n/a
br***********************@yahoo.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 discussion thread is closed

Replies have been disabled for this discussion.