[Twisted-Python] Suggested new module: twisted.internet.threadtask
itamar at zoteca.com
Mon Aug 13 13:23:41 EDT 2001
> Actually there is no need for using this class. And perhaps an
> additional scheduler module for threads only may be better than altering
> the existing one.
Okay, attached is a first shot at a task scheduler for threads.
Basically, tasks that are not thread safe should be added to this
scheduler, and then they will be called by the event loop.
I tested this by shutting off the synchronization in FileDescriptor, and
having my threaded server add all writes and closes to this scheduler
instead of calling them directly. It seemed to work fine, though CPU
usage seemed to be higher.
1) Make locking more fine-grained.
2) Just like classes can have a synchronized property with a list of
functions to be synchrnoized, I think there can be a scheduled property
as well, which would automate the following idiom for making thread-safe
operations using the scheduler:
def write(self, msg):
if not threadable.isInIOThread():
threadtask.schedule(self.write, (msg, ))
# regular write functionality goes here
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the Twisted-Python