A Piece of CherryPy for CGI Programmers
An anonymous reader writes "IBM developerWorks is running an article outlining the strengths and offering some helpful advice on the Python framework 'CherryPy'. CherryPy uses the same concepts as CGI to bind a web server to a web application, but it improves performance and gains persistence across requests by handling all its requests within a single process."
FastCGI anyone?
I have been doing that with python and perl for years. I can even run the CGI on multiple different hosts with one webserver.
that's a referral link in the parent post. To be honest, I'd recommend them anyway, but it's probably best to disclose it.
In the first few posts, I've seen a lot of relatively lacking-in-clue replies asking how CherryPy is different from ASP.NET, mod_python, FastCGI, etc. With most Apache-based web platforms, one process will handle many requests, but you cannot guarantee that every request will be handled by the same process: by default, apache starts multiple (possibly multi-threaded) servers, and creates and destroys them as necessary.
CherryPy, on the other hand, runs every request from the same process by using a thread pool instead of a process pool. This means that any global variables you change will be visible to any request. In many cases (keeping in mind memory restraints), you can share items in memory that would otherwise have to go through the database, which can help performance and make keeping track of state easier. Of course, multithreaded data sharing places its own demand on the programmer: the Python core is inherently thread-safe, but no programming language can protect you from race conditions and the like.
I've played around a little bit with CherryPy, and writing in it definitely feels Pythonic. It may still need some more development before it is fully mature, but it's something to at least keep an eye on.
(On a side note: I don't know how the IIS/ASP.NET process model works. It does let you store data across an application, but you are limited to a single Application hashtable, probably to be orthogonal to the Session and Viewstate objects and to reduce the likelihood that a programmer not experienced with concurrency would shoot him/herself in the foot.)
Friends don't let friends misuse the subjunctive.
Wow, tough crowd. Maybe Django does the trick for you? It does some unique stuff, and is python: http://www.djangoproject.com/
I'll got ahead and put in a plug for Nevow here, another web framework that is based on the EXCELLENT Twisted framework.
If you're doing any sort of network programming in Python, you need to look at Twisted.
Using SQLObject is very popular with CherryPy users. CherryPy works with just about any templating system out there. This also makes it very easy to port from other Python web frameworks because you can use your existing templates.
Subway was created to use CherryPy, SQLObject and Cheetah templates in a very Ruby on Rails-like way, so you don't have to go through the 10 zillion decisions of what to use with CherryPy and tells you "what to do and where to put it".
But of course, if IBM says it's new, well it must be ;-)
Okay, I checked, and I exagerrated a little bit, the earliest CVS version on mod_fastcgi.c is:
- "History shows again and again how nature points out the folly of men" -- Blue Oyster Cult, 'Godzilla'
Actually, Now that is also not quite true, because people have written various JVM bytecode compilers for their languages, or implemented their languages in Java. (See Jython for the latter, or The Tcl/Java Project, or The scheme package for Java based scheme. lists some 200 languages that have been ported to the JVM.)
> Put a function called hello() in your CherryPy application, and the return value of
> that function is displayed in your web browser when you visit http://address/hello
Rails and Struts already have this feature.
(Of course, for Struts you need a some XML for every class you want to act this way.)
Someone is, and it's called Subway: http://subway.python-hosting.com/
As an alternative, Quixote http://www.mems-exchange.org/software/ has a slightly different flavor to exposing Python objects via the url, probably a little more secure out of the box (including cross site scripting protection) and does XMLRPC in a straightforward manner.
as does perl's catalyst.
I'm assuming you didn't read the article, because it explains that CherryPy doesn't just call whatever function is passed in the URL. The programmer has to explicitly expose his functions to the CherryPy server instance. Otherwise, they won't be called. So unless for some reason you @cpg.expose rmdir or kill or any other system function (which you would obviously never do) this isn't an issue.
Lack of eloquence does not denote lack of intelligence, though they often coincide.
Beeep, wrong
Python is not based on any "java ideal", and everything in python is indeed an object, a module is an object, a function is an object, and "1" is an object by itself.
And it can't be compiled, it's a purely interpreted language, it's merely loosely syntax-checked and translated to bytecode (not compiled mind you, that's several steps under java). Some utils write machine code at "compile time" (Psycho), but it's not built in the base language in any way.
"The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
Relatedly I just released Paste Deploy, which is also intended to address these issues. It's just a small piece that will only be useful given more infrastructure support, but I'm optimistic. In the end I think it will mean some specific setup to support Python applications on a server, but once the basic support is configured adding an application should be a one-line affair.
>I use fastcgi with perl all the time. I love it, makes my apps very fast. Apache 2.0's "fcgi" module (fastcgi server component, but better maintained) works nicely almost out of the box.
;) )
You may also want to check out lighttpd. It's smaller and faster than apache on static content (dynamic content depends on cgi speed, I guess
---- MISSING MISCELLANEOUS DATA SEGMENT --- [sigdash] trolololol
"original features like being able to pass closures"
Lisp, anyone?
For instance, if your form has fields Name and Password with action="loginUser", you write this:And the arguments will be automatically passed. With CherryPy, your web app embeds its own multi-threaded web server; one practice is to put it behind Apache, so you can integrate it with already existing setups. It supports the Python Web Server Gateway Interface (WSGI) so you can use mod_python, IIS/ASP, FastCGI, SCGI , etc.
The ability to use Python makes web programming bearable again. Want something cool? SQLObject turns your SQL (MySQL, PostGres, others) into Python objects.What's more, you don't have to define your class in code. You can read it straight from the DB schema:You can also combine CherryPy with your choice of templating system. And for version control, check out how Trac works with SVN at the CherryPy site.
If you're sick of PHP, learn Python and enjoy programming again.
If you're like me and downloaded the latest cherrypy to follow along with the article, there's a quick fix that will make version 2.1 work with it. Just change any lines that say:
from cherrypy import cpg
to:
import cherrypy as cpg
More info here.
--- Hot Shot City is particularly good.
Leonard Richardson, who wrote the article in question, also recently wrote articles on SQLObject and Cheetah.
Not particularly, no, OO predates Java by far and considering in Java everything is NOT an object, their claim to that phrase is ridiculous at best. If "everything is an object" ideal comes from somewhere, it's Smalltalk.
Nor would I be particularly surprised if Python were quite object oriented from the beginning,