Re: httplib, threading, wx app freezing after 4 hours

2006-07-23 Thread Mark rainess
[EMAIL PROTECTED] 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
-- 
http://mail.python.org/mailman/listinfo/python-list


httplib, threading, wx app freezing after 4 hours

2006-07-22 Thread Mark rainess
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
=
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Download .jpg from web

2006-06-07 Thread Mark rainess
GMane Python wrote:
 Hello All.
   Using a network camera with built-in webserver, I'd like to have a python
 program download .jpg files on a local lan.  the location is
 http://ip-address/jpg/image.jpg.
 
   Currently, I'm importing urllib and using urlopen to the address, then
 read()-ing it, saving it to a binary file.  All that is working great, but
 maybe a bit slowly.  I'm getting ~2.3 frames per second, and would like
 between 5-10 frames per second.
 
   Am I approaching this incorrectly?  I have to do a urlopen, then .read()
 for each image.  Is there any way to 'persist' the urlopen so I just have to
 keep read()-ing or maybe is there a type of streaming read?  I have many
 cameras, so there are many threads simultaneously reading and dropping them
 in a central Queue for saving later.
 
   I appreciate it!
 -Dave
 
  WebImage = urllib.urlopen(http://ip-address/jpg/image.jpg).read()
  QueuePacket = []
  QueuePacket.append(WebImage)
 
 
 
 
What your doing, downloading images one at a time, is not the most 
efficient method. What you want to do is to enable the mjpeg (motion 
jpeg) mode of the camera. I am using a Trendnet camera. To get the mjpeg 
stream out of this camera, I use: camera-url/VIDEO.CGI. If you put 
this address into the Firefox address bar, and then press refresh (for 
some reason it doesn't start unless you press refresh) it will start. 
The camera will hold the connection open and send jpeg images as a 
multipart mime message.

The camera will respond with the header:

Server: Camera Web Server/1.0
Auther: Steven Wu
MIME-version: 1.0
Cache-Control: no-cache
Content-Type:multipart/x-mixed-replace;boundary=--video boundary--


Then it will repeatedly send send:

---
--video boundary--
Content-length: 27577
Content-type: image/jpeg

jpeg data

--video boundary--
---

I had a url with a good explanation of this but I can't find it now. If 
I find it I will post it.

Here is a simplified version of my current thinking.
I took out the error handeling stuff to make the logic
clear.


Thread that reads from the camera

h=httplib.HTTP(camera url)
h.putrequest('GET','VIDEO.CGI')
h.putheader('Accept','text/html')
h.putheader('Accept','image/jpeg') # Trendnet camera works without this
h.endheaders()
errcode,errmsg,headers=h.getreply()
f=h.getfile()
if errcode is 200 go on the the next part

while 1:
   data=f.readline()
   if data[0:15]=='Content-length:':
 count=int(data[16:])
 n=f.readline()  # skip over Content-type: image/jpeg\n'
 n=f.readline()  # skip over \n'
 s = f.read(count)
 p=file(tempfile,'wb')
 p.write(s)
 p.close()
 trigger main thread to display image from tempfile



The first part sets it up and the while loop gets the jpeg data
as fast is the camera will send it.

Mark Rainess
-- 
http://mail.python.org/mailman/listinfo/python-list


Multi-Monitor Support

2006-05-01 Thread Mark rainess
Hello,


Does Python or wxPython include any support for multiple monitors. In my 
application multiple monitors are located at a distance. It is not 
convenient to move a window from the main monitor to one of the others. 
I want to have the option to open an an application on any connected 
monitor. I am using wxPython. Does anyone know how to do it?

Thanks

Mark Rainess
-- 
http://mail.python.org/mailman/listinfo/python-list