[PEAK] Simplifying configuration for PEAK+Twisted apps
Phillip J. Eby
pje at telecommunity.com
Tue Jan 13 22:32:18 EST 2004
After thinking over the issues brought up by Bob Ippolito, and their
consequences for configuring a Twisted reactor for use with PEAK, I think
I'd like to propose to do the following:
* Define a property name whose truth is used to signal the "twistedness" of
a service area
* Add 'running.ifTwisted(ob,twistedValue,untwistedValue)', that returns
'twistedValue' if the service area containing 'ob' is configured to be used
with Twisted, or 'untwistedValue' otherwise.
* Add 'running.makeTwisted(ob)', which tries to configure the service area
containing 'ob' to be used with Twisted, or raises an error if the service
area has already been used in an "untwisted" fashion.
* Configure all of the appropriate event-management component factories
(running.IMainLoop, events.IScheduler, events.ISelector, and
running.IBasicReactor) to use 'ifTwisted()' to select an appropriate
implementation.
* Configure the running.ITwistedReactor component factory to invoke
'makeTwisted()' on the applicable service area before returning the
twisted.internet.reactor. This will have the unfortunate side effect of
having any lookups for 'config.FactoryFor(running.ITwistedReactor)' to
attempt forcing a Twisted configuration, but in practice I think the
sensible answer to this issue would be "don't do that."
With these changes, I think we could get rid of the current
'getTwisted()'/etc. kludges, and also avoid having to have a bunch of
manual component factory configuration operations in order to use a Twisted
reactor with PEAK. The net result is that no changes to current
PEAK+Twisted apps would be required, as long as you adhere to the current
constraint of looking up ITwistedReactor before any attempt is made to use
an IBasicReactor. IBasicReactor would still be phased out in a4, though,
since 'peak.events' will provide a superior alternative by then.
For apps that use Twisted with options like a GUI, "real" threads, etc., I
think there should probably be some way to get those options installed by
the ITwistedReactor factory. But I'm not familiar enough with the use
cases for those to be comfortable specifying a mechanism. Maybe it'd
suffice to do something like:
[peak.running]
twistedness = importString('twisted.internet.somereactor').install() or True
if you wanted to use a special Twisted reactor.
More information about the PEAK
mailing list