Slashdot Mirror


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."

8 of 193 comments (clear)

  1. Umm.. by Anonymous Coward · · Score: 3, Informative

    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.

  2. Whoops - sorry, to head off any criticism: by TDScott · · Score: 4, Informative

    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.

  3. What being in a single process really means by MostlyHarmless · · Score: 5, Informative

    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.
  4. Nevow by kevin_conaway · · Score: 4, Informative

    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.

  5. Re:Seems only useful if you already do Python CGI. by justrob · · Score: 5, Informative

    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".

  6. Gee, it sounds just like... by mengel · · Score: 3, Informative
    ... FastCGI which has had a several python modules for about 10 years...

    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:

    Revision 1.1 / (download) - annotate - [select for diffs] , Tue Sep 16 15:38:22 1997 UTC (7 years, 11 months ago) by stanleyg
    --
    - "History shows again and again how nature points out the folly of men" -- Blue Oyster Cult, 'Godzilla'
  7. Re:People are looking at this the wrong way by Beek · · Score: 3, Informative

    > 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.)

  8. Re:Bah, Scripting languages by masklinn · · Score: 3, Informative
    Python is an Object Oriented language experiment. An interpreted language that can be compiled. Based on the Java ideal without the "Everything is an Object", clearer syntax than Perl, and more consistency within the syntax (than Java).

    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