Python virtualization class

What is the meaning of decorators

 @reactor.callWhenRunning,
 @results_deferred.addCallback
 @results_deferred.addErrback.

Pending lines also apply, for example, in

 twisted.internet.utils.getProcessOutput()

returns a pending string, what exactly happens here?

I'm new to twisting, so this can be a very simple question, but reading the twisted documentation didn't help me.

+3
source share
3 answers

Deferral is like a promise to return the result in the future. You really should read the Deferreds documentation here and here . In addition, you should read about Python decorators in general. One introduction here .

, , getProcessOutput(), . . , , : , , , , . ( ) getProcessOutput , . , , , . , .

+3

db = Database.connect()
result = db.getResult()
processResult(result)

, , 3 .

, "".

, . , , . , ..

"" "".

result, Twisted Deferred. , , , /.

deferredResult = db.nonBlockingGetResult()
deferredResult.addCallback(processOutput)

, "-" . - Deferred. , . Deferred processOutput, , "" - .. result .

+4

I'm not sure about python, but it looks like an Active object and Futures pattern. Futures will be standard in the next version of C ++. If you read Active object and Futures, you get a view

+1
source

Source: https://habr.com/ru/post/1736671/


All Articles