473,594 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multi-threaded webcam with SimpleAsyncHTTP Server.py

The class seems to work pretty well - very basic and fast, it just
serves images from the specified port and camera device (USB cam).
I added an ImageServer class and some code to __main__

class ImageServer(Req uestHandler):
def __init__(self, conn, addr, server):
asynchat.async_ chat.__init__(s elf,conn)
self.client_add ress = addr
self.connection = conn
self.server = server
self.set_termin ator ('\r\n\r\n')
self.incoming = deque()
self.outgoing = deque()
self.rfile = None
self.wfile = writewrapper(se lf.outgoing,
-self.use_buffer or self.blocksize)
self.found_term inator = self.handle_req uest_line
self.request_ve rsion = "HTTP/1.1"
self.code = None

def send_head(self) :
buff, width, height = cam.dev.getbuff er()
imPIL = (Image.frombuff er("RGB", (width, height), buff,
"raw", "BGR", 0, -1) )
imPIL.save(PILF ile, "JPEG")
self.send_respo nse(200)
self.send_heade r("Content-type", "image/jpeg")
self.send_heade r("Content-Length: ", str(PILFile.len ))
self.end_header s()

self.wfile.writ e(PILFile.getva lue())
return
in __main__
....
parser.add_opti on('-3', dest='server',
help='Run the server for only cam images',
action='store_c onst', const=3)
....
if options.server= =3:
from StringIO import StringIO
from PIL import Image
if sys.platform == 'win32':
import VideoCapture
try:
del(cam)
gc.collect()
print "deleted old cam instance"
except: pass
cam = VideoCapture.De vice(devnum=opt ions.devNum,
showVideoWindow =0)
print cam
buff, width, height = cam.dev.getbuff er()
PILFile = StringIO()
else:
pass
else:
if options.root is None:
parser.error("N eed root path to start server")
if not os.path.isdir(o ptions.root):
parser.error("R oot path does not exist")
os.chdir(option s.root)

I run it with:
>python SimpleAsyncHTTP Server.py -p8888 -3
I'll be trying implementing some streaming next.
Question, though: how can I unblock asyncore.loop() , or at least be
able to interrupt it? To kill this server I need to hit CNTRL-C and
then attempt to GET an image from Firefox, Python then throws
KetboardInterru pt.

Note that I haven't tried it on *NIX so the sys.platform bit needs
more implementing as well.

Other suggestions?

Ray
Jan 8 '07 #1
1 1914
Ray Schumacher wrote:
I'll be trying implementing some streaming next.
Question, though: how can I unblock asyncore.loop() ,
Not at all. That's the way event loops work.
or at least be able to interrupt it?
Sorry for the stupid question, but why would you want to do that?
Other suggestions?
Yes, why do you call it multithreaded when it's multiplexing? (or
isn't it?)

Regards,
Björn

--
BOFH excuse #10:

hardware stress fractures

Jan 8 '07 #2

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

Similar topics

12
3857
by: * ProteanThread * | last post by:
but depends upon the clique: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=954drf%24oca%241%40agate.berkeley.edu&rnum=2&prev=/groups%3Fq%3D%2522cross%2Bposting%2Bversus%2Bmulti%2Bposting%2522%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den ...
0
3764
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black and white CCITT4 compressed files (frames) inside the tiff. Every now and then I receive a mixture of black and white CCITT4 and JPEG compressed files, and sometimes just multi-page tiffs with JPEG only. The code runs great when dealing with the...
6
8156
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
5
5735
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone know a good place to start looking for some theory on the subject of multi user applications? I know only bits and pieces, like about transactions, but a compendium of possible approches to multi user programming would be very appreciated!
0
624
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black and white CCITT4 compressed files (frames) inside the tiff. Every now and then I receive a mixture of black and white CCITT4 and JPEG compressed files, and sometimes just multi-page tiffs with JPEG only. The code runs great when dealing with the...
0
7947
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
7880
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
8374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8010
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
8242
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...
1
5739
isladogs
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...
0
5413
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();...
1
2389
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
0
1217
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.