From: Titus B. <ti...@ca...> - 2002-12-02 17:30:50
|
-> I have aolserver up and running with postgreSQL and PyWX. I have Quixote -> running on top of PyWX without Publisher() - just enable_ptl() -> -> But I am not clear from your last post on the list just exactly how to -> install the ThreadedPublisher - handler.Handle. I do have the latest -> 0.6 Quixote with your patches and I do have the latest Handler, and I -> do have the ns_param entry that you recommended -> -> Can you give me a blow by blow account of how to get it together (including -> what you use as the handler filename.) Sure -- I'll start by assuming that you have a functioning CGI setup, and can run scripts by putting them in the appropriate directory and calling them directly, e.g. http://localhost/script/hello-world.py Usually these scripts are running under interpreter mode, in which a new Python interpreter is used for each connection; this avoids any sort of cross-talk between instances of the script from namespace pollution, and mimics your normal CGI environment fairly well. Now, go to your config file and make sure you also have a 'thread' pool: you should see -- ns_param Pools "interp,thread,cgi" -- if you put the example Tcl into your configuration from the INSTALL file. You're going to use the 'thread' pool, which uses a single interpreter with multiple threads to serve Web pages. Also make sure that your PyWXPath variable contains the directory with Nspywx.so and *.py (from the PyWX distribution) in it; I usually put this in 'pywx-lib/' under the AOLserver install directory: -- ns_param PyWXPath "${homedir}/pywx-lib" -- Go find the ns_section for "ns/module/pywx/pool/thread". Here you want to make sure that you have the following commands: -- ns_param Mode Threaded ns_param PythonPath "/path/to/directory/with/your/quixote/package" -- where "your Quixote package" means *your* own code; the latest Quixote from CVS should be installed, or also placed in this PythonPath (: delimited). In this same section ("ns/module/pywx/pool/thread") put the command -- ns_param Setup "import handler" -- where "handler.py" is in your/quixote/package/ and looks like the attached 'handler.py'. This file should do the following: 1. create a Quixote publisher for your app ("app"); 2. create a handleQuixote.Handler instance: _handler = handleQuixote.Handler("base_url", app) 3. define a function 'handle' that calls '_handler.handle'. Now, assuming that all worked, the last thing you need to do is map that handler to a particular URL. Again in your .tcl configuration file, under the section "ns/server/${servername}/module/pywx/pool/thread", put the command: ns_param Map "* /base_url/* handler.handle" And voila, you should be done! Start AOLserver up and try going to /base_url/. Stepping back a bit, the object is to get /base_url/* mapped to a function that calls the appropriate publish() function on your Quixote publisher object. Most of this is just path setup and code setup to do that... Now that I've written it all out, I'm not surprised you were having trouble ;). I will try to put together a demo handler this week... -> And could you give me a little foresight into just how you can deal with the -> database handles that go with the threads? I use a Queue (Python std lib) to synchronize around grabbing database handles from a common pool. I don't use the standard ns_ methods for getting the handles in the first place, tho; I use 'psycopg' (initd.org/) instead. I can send you some source if you like. I hope all this helps ;). --titus |