![Programming Programming](http://a.fsdn.com/sd/topics/programming_64.png)
![IT IT](http://a.fsdn.com/sd/topics/it_64.png)
![Technology Technology](http://a.fsdn.com/sd/topics/technology_64.png)
A Piece of CherryPy for CGI Programmers 193
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."
You mean... (Score:5, Insightful)
This is nothing special. Just another framework that doesn't really do anything unique at all...
Re:You mean... (Score:2)
Re:You mean... (Score:3, Insightful)
Re:You mean... (Score:2)
Oh, and until we speak, you should pretend to be excited about a "new" "technology" that is single threaded and susceptible to the whole process crashing because the _one_ thread it uses dies.
Re:You mean... (Score:2)
Re:You mean... (Score:2)
What was that about having an IQ above 80 that would help you understand someone being facetious [reference.com] (I know, it is a big word for you) vs. being serious?
Oh, and thank you "Captain Obvious" for telling us that:
I really wish /. would require a simple IQ test before someone coul
Re:You mean... (Score:2)
these days, one process can host a myriad of threads, each doing their own thing
Guess what I was being? That's right, facetious [reference.com]! Congratulations.
I only replied because I didn't find your comment very funny, and I don't like people who put pretentious things like "Senior Programmer" in their signature, if I wanted to know what your title at work was, I would ask you; otherwise, I'll judge what I think of you by what you sa
Re:You mean... (Score:2)
Oh, you just like people who put "witty" sayings in their sig such as yours?
Heh, heh, heh. That is just great. I bet your just "the" elite /. user aren't you? Boy, I wish I could have come up with a great sig like yours! I bet your some 133t hacker huh?
Ahh, yes, your sig is a well structured a
CGI's my cherry pie (Score:3, Funny)
Re:CGI's my cherry pie (Score:2)
Re:You mean... (Score:3, Insightful)
Re:You mean... (Score:2)
Anyway, what's "hot" in Python for web currently is Django.
Re:You mean... (Score:2)
Re:You mean... (Score:2)
Reminds me too much about CherryOS... Not good.
Re:You mean... (Score:5, Interesting)
Re:You mean... (Score:2)
Python is a much better language for writing complex
Re:You mean... (Score:3, Insightful)
Re:You mean... (Score:3, Informative)
You may also want to check out lighttpd [lighttpd.org]. It's smaller and faster than apache on static content (dynamic content depends on cgi speed, I guess
Obligatory (Score:5, Funny)
Re:Obligatory (Score:2, Insightful)
face.smile.width.units = "Miles"
face.smile.width = 10
Re:Obligatory (Score:2)
Re:Obligatory (Score:2)
Re:Obligatory (Score:2)
Re:Obligatory (Score:4, Insightful)
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=1;b=2
>>> a
1
>>> b
2
>>>
Re:Obligatory (Score:2)
oh god...
May i ask a mod passing by to mod all my previous posts of this thread "-1 fucktard"? thank you
Re:Obligatory (Score:2)
PyDie (Score:2, Funny)
So, we now have (Score:3, Insightful)
Regular CGI, mod_perl, mod_python, the newcomer Ruby on Rails, and now CherryPy. Granted, some webhosts [dreamhost.com] handle the first four (even Rails) without any problems, but how many do we really need?
I suppose the answer is "as many as it takes" — whatever's easiest for some users will be utterly impenetrable to others, and it's good to have choice. But at what point does it start to become a burden to keep up with all these — either for programmers looking to keep their CVs up to date, or hosts wanting to stay current?
Whoops - sorry, to head off any criticism: (Score:5, Informative)
Re:Whoops - sorry, to head off any criticism: (Score:2)
Their referral script is obviously either very dumb or very cunning.
Re:Whoops - sorry, to head off any criticism: (Score:2)
Re:Whoops - sorry, to head off any criticism: (Score:2)
Re:So, we now have (Score:2)
No, the answer is more than it takes. (Score:2)
And if a webhost is any good, they don't have to keep everything up to date f
Umm.. (Score:3, Informative)
I have been doing that with python and perl for years. I can even run the CGI on multiple different hosts with one webserver.
Re:Umm.. (Score:2, Interesting)
Can anybody show me that Py
Plodding Python? (Score:3, Interesting)
A similar thing applies to web apps - a slow web app is usually due to high-level design errors, not a slow scripting language. A lot of web apps spend most of their time in database calls. When an app is blocked on I/O, it's just as fast in Python as in C, much like a Porsche stuck nex
Re:Umm.. (Score:2)
Re:Umm.. (Score:2)
"What fun! April Fool's Day all year long! Can you manipulate the multipliers and weights to make your favourite language the fastest programming language in the Shootout?
And remember, languages that implement more benchmarks will move to the top of the list, and those with many missing benchmarks will stay at the bottom!"
That said, in the direct comparison there are no places where perl uses less memory or CPU than python, so you can't fudge
WTF are you talking about? (Score:2)
Frankly I don't think python is a contender for CGI programming. Nor do I think perl or any other interpreted language is. Stop using CGI, its 2005 for fuck's sake.
Re:Umm.. (Score:2)
Python is fast enough for most applications, and it has improved significantly in the latest releases, 2.3 and 2.4. It's not much slower than perl and is a much nicer language, IMHO. I've used it on countless projects without problem or performance issues.
If performance is your primary concern, you wouldn't be using python, and you wouldn't be using CGI obviously so the question is not so relevant, I think.
As for emerge, it's slow response comes from the non optimized way it scans a databas
Give me a reason to use this (Score:2, Interesting)
-m
Re:Give me a reason to use this (Score:3, Interesting)
Re:Give me a reason to use this (Score:5, Interesting)
What being in a single process really means (Score:5, Informative)
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.)
Re:What being in a single process really means (Score:3, Informative)
ASP.NET uses a single process for each application. Every request is processed by the sa
That's the same thing as a servlet (Score:2, Redundant)
Re:That's the same thing as a servlet (Score:2)
Re:What being in a single process really means (Score:2)
1) python multithreaded scalability is limited by the global interpreter lock.
2) With a multi-process model you can use memcached to cache stuff in memory without going via the DB. Additionally, with this architecture horizontal scaling is also possible.
3) A multi-process model is pretty robust. If one process dies, apache restarts it. If your application, or the app framework etc. suffers from a memory leak, you can configure apache to let each process handle onl
Re:What being in a single process really means (Score:2)
Like with shared memory? But shared memory also works with multiple processes. And if you've more than one webserver (scaling and stuff) you still need a central data storage, like a database or a simpler session storage (i.e. msession).
b4n
People are looking at this the wrong way (Score:5, Interesting)
What makes this cooler is that Python functions are exposed in the URL. Read through that IBM tutorial. It's fairly interesting. 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 [address]
I don't know about you, but I think that's pretty cool. You could definitely do some interesting stuff with this, and I can see it saving a lot of time in the code-writing phase. And once you get your head wrapped around that concept pretty well, the design phase would probably get a lot shorter too. (Not to mention how much easier it would then become to add new features to the application.)
This is interesting for two reasons: Python frameworks are now catching up to things like ASP and PHP, but are doing some crucial things differently that might make it much easier/more powerful. I might start using this instead of PHP for small web apps that just need to talk to a database, and see how it goes from there.
Re:People are looking at this the wrong way (Score:2, Insightful)
That's wrong on so many levels. For starters, ASP (assuming you mean ASP.NET) is lightyears ahead of anything python simply because it gets compiled into machine code before it's executed and runs "closer to the iron" (and therefore blows the doors off anything interpreted). I could name five dozen other reasons why ASP.NET and similar Java based frameworks are better, but I don't want to waste time. There's google, you can find it you
People are looking at this the wrong way (Score:4, Interesting)
And actually I don't know of any java frameworks that don't require tons o' xml flinging to get up and running. Please feel free to enlighten me.
Re:People are looking at this the wrong way (Score:2)
You are correct, but neither have the ease of use and the speed of application development that Rails has. Given this development however, I'd be surprised if someone isn't hammering out a Rails-esque framework for Python as we speak! :)
Re:People are looking at this the wrong way (Score:2, Informative)
Re:People are looking at this the wrong way (Score:2)
btw, your home page link (http://www.jaredcam.net/ [jaredcam.net] goes to the default Apache greeting instead of a real page. FYI...
Re:People are looking at this the wrong way (Score:4, Insightful)
Re:People are looking at this the wrong way (Score:2)
Struts is a piece of shit and probably the worst java framework available...
Oh, and if you run it on top of Tomcat you're doomed...
Re:People are looking at this the wrong way (Score:2)
Matt Raible's Comparison of Web Frameworks [java.net] would be a good start for you, along with the Equinox demo [java.net]
Re:People are looking at this the wrong way (Score:3, Informative)
Actually,
Re:People are looking at this the wrong way (Score:2)
Ok so you're code is running faster. And that brings you? Nothing. You're code is just waiting faster for data from the network or the database or the filesystem. If your code is good it doesn't matter if it's written in PHP, ASP, Python, Perl, Ruby,
so wrong (Score:2)
Machine code, yes. Only it is machine code ( bytecode ) for the CLR (
BTW, i worked about a year on a system upgraded from ASP ( interpreted VBScript ) to ASP.NET ( bytecode compiled C# ). We wrote it from scratch, and only used t
Re:People are looking at this the wrong way (Score:3, Informative)
> that function is displayed in your web browser when you visit http://address/hello [address]
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.)
Don't forget Catalyst! (Score:2)
Don't forget Catalyst [perl.org]!
Of course, being later to the game allowed Catalyst to one-up the competition with the utmost in flexibility: full regex-based URL handlers!
Re:People are looking at this the wrong way (Score:3, Interesting)
rm -Rf (Score:2)
http://www.site.com/rmdir [site.com]
http://www.site.com/mke2fs?/dev/sda [site.com]
http://www.site.com/kill [site.com] `pidof httpd`
Re:rm -Rf (Score:3, Informative)
Ahhh, injection attacks (Score:2)
Re:People are looking at this the wrong way (Score:3, Insightful)
While Python web programming has some issues, "catching up" isn't really how I'd describe it. Even in the most basic of Python frameworks you get more expressive power than in ASP and PHP. You also get equivalent performance to PHP (I can't say much about ASP -- but Python is fast enough which is all that matters). In terms of expressiveness Python beats the pants off PHP, Visual Basic, C#, and Java. There's no "catching up" there at all,
Cool! (Score:5, Interesting)
Re:Cool! (Score:4, Interesting)
Nevow (Score:5, Informative)
If you're doing any sort of network programming in Python, you need to look at Twisted.
" All it does is..." (Score:5, Interesting)
And then in the very next paragraph, it says: "Instead of relying on Apache or another Web server, CherryPy runs its own small Python-based Web server."
No, no, no!
I love CherryPy as a way of routing requests to Python objects and functions. Rock on!
But look, I'm running like 20 wiki [taoriver.net] and 5 custom web apps and a few WordPress [wordpress.org] installations on my server. [taoriver.net]
And they are all plugged into Apache.
So, actually, in fact, CherryPy has now made some decisions about what tools I'm supposed to use.
Sure, I can forward requests from Apache to the CherryPy server, but that is yet another hassle, it is yet another thing to support and maintain and think about.
I wish instead that the CherryPy dev's had made it so there were multiple adapters to the CherryPy system.
All that said:
CherryPy is my favorite system for doing web apps in Python. I've used it, I've loved it, it's great. It does make programming WebApps "fun," which is perverse. So, it's succeeded.
But I strongly dislike how I have to do this funny Apache business to get it to run on port 80, or I have to give people weird 8080 addresses, like you saw in the article.
Another thing I dislike, is that it's kind of tricky to get it to do XML-RPC, in my experience. (Then again, that was 3 months ago. Perhaps things have changed now.)
(I just use AutoXmlRpcServer [python.org] or AutoXmlRpcCgi [python.org] for when it's XML-RPC alone, without a web side along with it.)
But again: CherryPy is my favorite, when there is no XML-RPC aspect, and when I don't mind the weird config stuff I have to do to get it to cooperate with Apache.
Wow, dude. Chill. (Score:4, Insightful)
Get a grip.
Re:Wow, dude. Chill. (Score:3, Interesting)
It's:
Re:Wow, dude. Chill. (Score:2, Insightful)
Well, duh.
Anyway it's all here: CherryPy behind Apache [cherrypy.org]
Re:" All it does is..." (Score:2, Funny)
You could put more than one thought.
On each line.
Re:" All it does is..." (Score:3, Informative)
Relatedly I just released Paste Deploy [pythonpaste.org], 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 optimist
Re:" All it does is..." (Score:2)
And then in the very next paragraph, it says: "Instead of relying on Apache or another Web server, CherryPy runs its own small Python-based Web server."
No, no, no!
I love CherryPy as a way of routing requests to Python objects and functions. Rock on!
But look, I'm running like 20 wiki and 5 custom web apps and a few WordPress installations
Seems only useful if you already do Python CGI. (Score:3, Insightful)
This is kind of a problem though because I actually need a templating system, database mapper, and some other tools. I have some such tools in Perl, but I obviously can't take these with me into Python.
So I am wondering. Were one to use CherryPy, what would be logical tools to build on top of it with? If I need to be able to take objects and convert them into lines in a database or HTML for display or HTML forms for editing or whatnot, what would be the logical things to plug in on top of CherryPy to provide this?
Re:Seems only useful if you already do Python CGI. (Score:5, Informative)
Subway [python-hosting.com] 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".
Re:Seems only useful if you already do Python CGI. (Score:3, Informative)
Gee, it sounds just like... (Score:4, Informative)
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:
Obligatory Quip (Score:2)
not so easy (Score:2)
django! (/. missed the hype train) (Score:5, Interesting)
I find CherryPy's URL traversal scheme a bit clunky -- since you connect up objects to each other via attributes, you can't see the hierarchy of your site. At least with PHP you can use "ls" to discover what your URL space looks like. Django uses a really neat scheme that binds a table of named regular expressions to callable handlers, e.g.
(r'^polls/(?P<poll_id>\d+)/$', 'myproject.apps.polls.views.polls.detail')
and the handler is declared as
def detail(request, poll_id)
...
Re:django! (/. missed the hype train) (Score:3, Interesting)
It's a very new project, so I don't think it's been used in any Python framework yet. But it would probably be applicable to quite a few of them (perhaps including CherryPy).
hmm, maybe .. (Score:2)
Why not just embed the python interpreter in an apache module ....
Re:hmm, maybe .. (Score:2)
For windows users... (Score:2, Funny)
80's flashback (Score:2, Funny)
Shameless Plug (Score:2)
I run a project that aims to be a java port of CherryPy. Supports all free vms and is very lightweight.
OOWeb [sf.net]
Quick fix for 2.1 (Score:3, Informative)
from cherrypy import cpg
to:
import cherrypy as cpg
More info here [cherrypy.org].
she's my..... (Score:2, Funny)
Re:Bah, Scripting languages (Score:2)
Your questions seem nonsensical, excepting this one. I'm just talking off the cuff here, but if someone asked me this aloud I might say...
Perl was initially for sorting, reading, rearranging text. It was expanded, logically into being an apache module. Apache serves plaintext HTML documents. Perl expanded its feature set in every direction...a proverbial hammer for any kind of problem. Other languages suffer f
Re:Bah, Scripting languages (Score:4, Informative)
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.
Re:Bah, Scripting languages (Score:2)
I didn't imply it was based on Java or a Java idea. The idea that "everything is an object", is the Java ideal that I spoke of. Python is now specifically based on the Java ideal when it initially was simply extensible. Does that sound about right?
Re:Bah, Scripting languages (Score:2)
It's called having direction. If the language implements features of other languages, I find it fair to say it's based on a common denominator. I read the history of Python (from the python.org faq) before posting. My viewpoint hasnt changed.
As an aside, nothing I've heard about Python in this discussion has increased my respect for Python as a language. What is the strength of Python? The Python FAQ topic 1.1.3 What is Python good for? a
Re:Bah, Scripting languages (Score:2)
Features, object orientation, philopophy (you don't code in Ruby or Python the way you'd code in Perl, and you don't code in PHP at all if you can avoid it)
Re:Very nice framework... (Score:2)
Put this as x.conf:
[server]
socketPort = 8080
socketHost = 127.0.0.1
threadPool = 10
Then do a cpg.server.start('x.conf')
and see what happens.
I mean, really, did you think someone would publish a web framework that could only handle 1 concurrent request? Are you stupid?