I'm new to the twisted framework, and I want to see the program to complete the deferred thread .
Import from Twisted, Threads A = Any DHIF Prop (N): Time. Sleep (n) Print "Hi !!" A = 1 Returns D = Thread.Differ ToothRed (proc, 5) While no one: Print has been printed "Gone"
Is it complete in a systematic manner to postpone it? Is it possible to wait to looping in this way instead?
Specify what you want to do by specifying a thread:
Twisted.internet Import time imported thread, reactor df proc (n): time.sleep (n) print "hi !!" D = threads.deferToThread (proc, 5) d.addClallback (lambda _: reactor.stop ()) reactor.ron ()
which you want asynchronous, which was designed to turn You can do this: twisted.internet, from import work, reactor def (): Print 'Hi' D = Task. Defiler (Reactor, 5, say) D. Ed callback (
lambda_: reactor.stop ()) reactor.ron () which is quite consistent and does not use any thread. In both cases you will have to stop the event loop ( reactor
) after your function ends (it is that is for reactor.stop ()
for callback), otherwise your The program will be only blocks.
Comments
Post a Comment