[Twisted-Python] questions about twisted usage

Uri Okrent uri.okrent at xtremio.com
Thu Mar 22 06:20:37 EDT 2012


Hello all, I'm a twisted novice, but I was brought on to a project
where twisted is pretty heavily in use.  I'm running into all sorts of
issues that make me wonder if we're using twisted properly or as it
was intended.  I have been through the documentation, but I think I
need more in-depth answers.  So here are a bunch of general questions
about twisted.  Once I understand this stuff I think I might be able
to ask more cogent questions about my specific implementation (or
maybe understand why things are the way they are).

1. Is deferToThread running the function in a real python thread?
Should this be used (rather than a standard deferred) for any function
that might block?
2. I understand that deferreds run "later".  However, once a deferred
(or a deferToThread) is picked up and run, does it run from start to
finish?  Can it be interrupted in the middle of the function?  How
about its callback/errback?  Can another deferred jump in for
processing in between a deferred and it's callback/errback, or in the
middle of processing another deferred?
3. Are there any guarantees regarding the order of execution of
deferreds? (I.e., are deferreds processed in the order in which they
are created?)
4. Related to #2, and #3, does it make sense to use twisted when
requests that are serviced may depend on one another.  For example, a
client makes a request 'add-A' which is deferred (so that the server
can keep processing requests), and immediately afterwards makes a
request 'modify-A' (which is also run as a deferred).  Can I count on
add-A being done so that modify-A doesn't attempt to work on something
which hasn't been created yet?
5. Related to all of the above.  What If I want to modify a database
inside a deferred?  Is that incorrect usage?  Specifically, if all my
requests run as deferred, and they all start a transaction and the
beginning, and commit the transaction at the end, will I run into
problems due to context switching in the middle of deferreds? (such as
one request committing for both requests, starting two transactions in
a row, committing twice in a row, and so on.)

Thanks in advance.  Please let me know if I'm so off that my questions
don't even make sense =)


-- 
  Uri

Please consider the environment before printing this message.
http://wwf.panda.org/savepaper/



More information about the Twisted-Python mailing list