[Twisted-Python] questions about twisted usage

Uri Okrent uri.okrent at xtremio.com
Thu Mar 22 08:34:41 EDT 2012

On Thu, Mar 22, 2012 at 2:17 PM, Itamar Turner-Trauring
<itamar at itamarst.org> wrote:
> On 03/22/2012 08:05 AM, Uri Okrent wrote:
>> This implies that twisted can (and will) switch contexts from one
>> deferred to another even in the middle of execution of the first
>> deferred, correct?
> No. Deferreds are just slightly nicer callbacks. They have nothing to do
> with the event loop, or scheduling, or context switching.

Maybe I should clarify my question:

thing = 0
def a():
    thing += 1
    thing += 1
    thing += 1
    thing += 1
    thing += 1

def b():
    thing = 0

def show_thing():
    print thing


given the two deferreds 'a' and 'b', with 'a' being called first, it
is possible for twisted to jump to 'b' in the middle of 'a' correct?
I.e., when show_thing runs after 'b' is finished it will always print
0 because thing was set to 0 by 'b', but when show_thing runs as the
callback for 'a', it will print something between 0 and 5 and it is
non-deterministic, because 'b' may have jumped in at some point during
the execution of 'a' and reset 'thing' back to 0.

Please consider the environment before printing this message.

More information about the Twisted-Python mailing list