[PEAK] Re: PEAK design pointers
pf_moore at yahoo.co.uk
Sun Mar 7 10:29:34 EST 2004
"Phillip J. Eby" <pje at telecommunity.com> writes:
>> > Well, if I understand you correctly, I'd probably write something that
>> > would spawn an events.Task for each of the databases to be monitored,
>> > and create another Task that accepted the results of each of the other
>> > tasks in order to prepare the consolidated report and mail it out.
>>Right - it sounds like events.Task is the place for me to look. That's
>>excellent. As I said, it's pointers to the right places to look which
>>I was lacking...
> Note that normally the way you'll do tasks is to wrap an object method
> with events.taskFactory. E.g.:
> def someMethod(self,...):
> # blah blah
> yield something; events.resume()
> # ...
> someMethod = events.taskFactory(someMethod)
> Then, calling 'someMethod(...)' will return a running 'events.Task'
> for that invocation of the method.
Hmm, I've read the events module, and as far as I can see it's aimed
at a cooperative multitasking model. That doesn't seem to fit my
application structure at all.
On the other hand, your suggestion of using Twisted's deferToThread
does help a lot. (I never thought of using Twisted for a non-network
I'll give you some detail of the simplest of my applications. Maybe
it will make things clearer. I won't try to include PEAK style
configuration or binding, as I think it'd only obscure the issue at
the moment. (And I think I know how to handle that)
Assume I have a generator function DBs(), which generates a series of
cx_Oracle connect strings, one after the other. My trivial application
just wants to try to connect to each, and report all the failures.
errors = 0
errors += 1
for db in dbs:
d = threads.deferToThread(cx_Oracle.connect, db)
# Really, stop when all threads have run
# Placeholder. Really send an email
The more complex applications will use a callback on the deferred to
save some query results in the repository.
I'm not sure I see a need for PEAK tasks here. Then again, using
twisted's reactor simplified the whole application so much that maybe
I don't need anything that complex now!
This signature intentionally left blank
More information about the PEAK