扭曲:DeferredList与collectResults

时间:2019-02-21 10:49:15

标签: python-3.x twisted modbus twisted.internet pymodbus

我正在尝试使用DeferredListgatherResults创建Deferred对象的列表。在使用这两种方法时,我发现了不同的结果。我正在使用pymodbus 2.1.0Twisted 18.4.0库。

参考链接::我已引用此链接Deferred Reference - Twisted Matrix Labs (18.4.0)

  

DeferredList用例:
  当我将DeferreListconsumeErrors=True一起使用时,将调用Deferred回调的结果,然后执行callback中的DeferredList。如果Deferred对象中有任何错误,则不会执行errorback中的DeferredList

DeferredListCallback结果:当没有可用的Modbus设备读取数据时,以下是DeferredList的结果。

INFO:service.TestService: (2019-02-21 15:58:39; TestService.py:21 Reading HRs of Modbus RTU device...)
INFO:__main__: (2019-02-21 15:59:09; Test.py:125 Reading HRs of Modbus RTU device completed successfully.)
INFO:service.TestService: (2019-02-21 15:59:09; TestService.py:32 Reading IRs of Modbus RTU device...)
  

gatherResults用例:   在gatherResults的情况下,所有Deferred对象的成功执行是对gatherResults的回调。如果在执行任何Deferred对象时发生错误,则将调用errorback并在控制台上打印stacktrace。

gatherResultsErrorback结果:以下是gatherResults对象之一试图从不可用的Modbus设备读取数据时Deferred的结果。

INFO:service.TestService: (2019-02-21 15:58:39; TestService.py:21 Reading HRs of Modbus RTU device...)
INFO:__main__: (2019-02-21 15:50:38; Test.py:212 Error reading HRs of Modbus RTU device : [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.defer.FirstError'>: FirstError[#0, [Failure instance: Traceback: <class 'twisted.internet.defer.TimeoutError'>: (30, 'Deferred')
C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\defer.py:385:timeItOut
C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\defer.py:544:cancel
C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\defer.py:500:errback
C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\defer.py:567:_startRunCallbacks --- <exception caught here> ---     C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\defer.py:653:_runCallbacks
C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\defer.py:394:convertCancelled
C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\defer.py:860:_cancelledToTimedOutError ]]].)

我不了解内部实现。为什么这两种不同的结果在同一情况下。什么时候应该使用?哪两个最好?

有人可以对此考虑清楚吗?

0 个答案:

没有答案