The PEAK Developers' Center   IrcHighlightsFiveTips UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
The following 186 words could not be found in the dictionary of 50 words (including 50 LocalSpellingWords) and are highlighted below:
Abstract   Adaptive   And   Assembly   Command   Config   Courtesy   Delegate   Driven   Event   Fast   If   In   Instead   Jabber   Make   Namespace   Obtain   Reactor   Runner   Site   So   Something   Specifically   Task   There   They   This   Tip   True   Twisted   Use   Wisted   You   actually   after   all   also   an   and   any   app   are   as   assembly   automatically   based   be   been   bind   binding   bindings   bunch   by   can   case   cause   class   command   commands   component   components   config   configuration   create   creating   creation   custom   define   delay   describe   directly   do   don   down   either   end   ensure   error   etc   events   extensions   fact   flat   for   handy   has   have   helpful   hook   hooks   host   how   idle   if   import   in   instance   instead   is   it   items   just   kind   kinds   lambda   like   line   listen   listeners   ll   long   map   means   meat   method   mini   myapp   names   namespace   need   new   not   now   objects   of   on   or   other   override   password   period   pje   port   precisely   properties   property   reactor   receiver   register   resource   run   running   same   schema   self   services   set   should   shutting   simple   some   someday   something   specific   start   stuff   svc1   svc2   tasks   that   the   them   then   these   they   things   this   time   tip   to   touching   trapping   up   upon   use   user   uses   using   was   well   whatever   which   will   you   your  

Clear message


Courtesy of pje:

1)

If you have a bunch of properties in a namespace that you need to bind to, you can do something like this: 
myapp = binding.Make(lambda: config.Namespace('myapp')) 
And then all the things that use the property namespace can bind to it, e.g.: 
port = binding.Obtain('myapp/receiver-port') 
user = binding.Obtain('myapp/user') 
etc. 
In fact, if your items are all in a "flat" namespace like that, and the items map precisely to the same property names,  
you can actually use Delegate: 
user = password = resource = host = binding.Delegate('myapp') 
So that was tip #1.
2) Tip #2...
don't import the Twisted reactor directly. 
Instead, use reactor = binding.Obtain(running.ITwistedReactor) 
This will ensure that any PEAK components will end up using the Twisted reactor, instead of PEAK's mini-reactor. 
E.g., if you use AdaptiveTask, or FastCGIRunner, or stuff like that.
3) Tip #3...
don't override AbstractCommand.run(), override the _run() method instead. 
run() now has handy error trapping, and it may someday have some other helpful hooks. 
You can just override _run() to define the "meat" of your command-line app.
4) Tip #4, and this is kind of specific to Twisted...
Use assembly events to set up listeners and tasks. 
Specifically, in the case of the Jabber and Site objects... 
You can set up binding.Make(lambda self: self.doSomething(), uponAssembly=True) 
bindings in these kinds of services that will cause them to register or start or listenTCP or whatever. 
They should have a 'reactor = binding.Obtain(running.ITWistedReactor)' as well, and use that to hook up to the reactor. 
A component that uses them can either delay creation (by not touching the binding), or define the binding as uponAssembly, 
 in which case they'll start ASAP.
5) Tip #5...
instead of creating a custom app class, use running.commands.EventDriven. 
This can be as simple as creating an instance of EventDriven(components=[svc1(), svc2(), ...]) 
EventDriven has configuration properties for things like automatically shutting down after a time period, or based on how long the app's been idle. 
There's also a ZConfig schema for EventDriven, which means that you can create ZConfig schema extensions to describe your new services.

PythonPowered
EditText of this page (last modified 2003-11-16 12:51:44)
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck