[Pythonmac-SIG] pythonw stay open
hengist.podd at virgin.net
Wed Dec 7 20:44:52 CET 2005
Christopher Barker wrote:
>>CGI's always going to be expensive as it starts a new process for each request. And yeah, if it's a GUI process then the overheads will bite even more.
>Yes, but it sounded like the OP was getting over a second start-up time. This is very long, so I wonder if something else is going on.
Oh, absolutely. OMM (not the fastest, admittedly) it probably takes a quarter of a second to import appscript (Python hauls in a big chunk of Carbon at that point). There's another quarter-second overhead in creating your first app instance (can't remember why offhand, but a profiler will tell you).
If ASTS is running then it's clear sailing the rest of the way thanks to ASTS's terminology caching.
If ASTS isn't running then there's a further quarter-second penalty on connecting to the first app as OSAGetAppTerminology() has to instantiate an AppleScript component before it can retrieve aete resources (stupid, I know; blame Apple's API). Plus there's the time it takes to retrieve the terminology (some Cocoa apps generate it on the fly from Cocoa Scripting data, making this even slower) and parse it (appscript is pretty fast at this, but it's still only Python) for each application the script uses; some heavyweights may well take over a second. Though you can avoid these particular overheads by only using aem, since it doesn't use terminology; aem code just takes a little more work to write.
>Have you looked at your memory use under that load?
>Otherwise, there are many web frameworks for Python, most of which provide some way to keep the python process persistent. I don't see why you couldn't use any of those.
>We're using Quixote successfully on OS-X, you also might want to look into wsgi and paste.
I'd be interested to know myself if anyone has used appscript/aem in a web framework context. (I'm not a web-head, so haven't explored this area myself.) Shoving the application scripting stuff into a persistent GUI process and using a light[er]weight IPC system to bridge between this and the CGI script is always an option. But having it in the main web app would be simpler and more efficient, assuming the web app uses a suitable Python distribution, of course (you won't get far without the Carbon extensions, obviously).
More information about the Pythonmac-SIG