summaryrefslogtreecommitdiff
path: root/pysnmp
diff options
context:
space:
mode:
authorEugene M. Kim <astralblue@gmail.com>2017-10-05 03:14:14 -0700
committerIlya Etingof <etingof@gmail.com>2017-10-05 12:14:14 +0200
commitb05edd892dff22c6651f00358f21f33520f2cda2 (patch)
tree50b5ef4a7426cd0704b743e9e0a73890f02da086 /pysnmp
parentb8187b8c1c30ff412b430667ad03ace99660eedd (diff)
downloadpysnmp-git-b05edd892dff22c6651f00358f21f33520f2cda2.tar.gz
Catch and pass exceptions to asyncio futures (#82)
Previously an exceptions raised by vbProcessor.unmakeVarBinds() fell through, and asyncio base event loop caught and reported it on stderr, while the original cmdgen's future went unfinished, causing the call to hang forever. Match the synchronous version's behavior, which is to raise the exception for the caller of the cmdgen to catch.
Diffstat (limited to 'pysnmp')
-rw-r--r--pysnmp/hlapi/asyncio/cmdgen.py54
-rw-r--r--pysnmp/hlapi/asyncio/ntforg.py12
2 files changed, 49 insertions, 17 deletions
diff --git a/pysnmp/hlapi/asyncio/cmdgen.py b/pysnmp/hlapi/asyncio/cmdgen.py
index a57f2ff3..9e732062 100644
--- a/pysnmp/hlapi/asyncio/cmdgen.py
+++ b/pysnmp/hlapi/asyncio/cmdgen.py
@@ -134,9 +134,15 @@ def getCmd(snmpEngine, authData, transportTarget, contextData,
lookupMib, future = cbCtx
if future.cancelled():
return
- future.set_result(
- (errorIndication, errorStatus, errorIndex, vbProcessor.unmakeVarBinds(snmpEngine, varBinds, lookupMib))
- )
+ try:
+ varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds,
+ lookupMib)
+ except Exception as e:
+ future.set_exception(e)
+ else:
+ future.set_result(
+ (errorIndication, errorStatus, errorIndex, varBindsUnmade)
+ )
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
@@ -233,9 +239,15 @@ def setCmd(snmpEngine, authData, transportTarget, contextData,
lookupMib, future = cbCtx
if future.cancelled():
return
- future.set_result(
- (errorIndication, errorStatus, errorIndex, vbProcessor.unmakeVarBinds(snmpEngine, varBinds, lookupMib))
- )
+ try:
+ varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds,
+ lookupMib)
+ except Exception as e:
+ future.set_exception(e)
+ else:
+ future.set_result(
+ (errorIndication, errorStatus, errorIndex, varBindsUnmade)
+ )
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
@@ -336,10 +348,17 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData,
lookupMib, future = cbCtx
if future.cancelled():
return
- future.set_result(
- (errorIndication, errorStatus, errorIndex,
- [vbProcessor.unmakeVarBinds(snmpEngine, varBindTableRow, lookupMib) for varBindTableRow in varBindTable])
- )
+ try:
+ varBindsUnmade = [vbProcessor.unmakeVarBinds(snmpEngine,
+ varBindTableRow,
+ lookupMib)
+ for varBindTableRow in varBindTable]
+ except Exception as e:
+ future.set_exception(e)
+ else:
+ future.set_result(
+ (errorIndication, errorStatus, errorIndex, varBindsUnmade)
+ )
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
@@ -451,10 +470,17 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData,
lookupMib, future = cbCtx
if future.cancelled():
return
- future.set_result(
- (errorIndication, errorStatus, errorIndex,
- [vbProcessor.unmakeVarBinds(snmpEngine, varBindTableRow, lookupMib) for varBindTableRow in varBindTable])
- )
+ try:
+ varBindsUnmade = [vbProcessor.unmakeVarBinds(snmpEngine,
+ varBindTableRow,
+ lookupMib)
+ for varBindTableRow in varBindTable]
+ except Exception as e:
+ future.set_exception(e)
+ else:
+ future.set_result(
+ (errorIndication, errorStatus, errorIndex, varBindsUnmade)
+ )
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
diff --git a/pysnmp/hlapi/asyncio/ntforg.py b/pysnmp/hlapi/asyncio/ntforg.py
index f7bd7c90..d0580f66 100644
--- a/pysnmp/hlapi/asyncio/ntforg.py
+++ b/pysnmp/hlapi/asyncio/ntforg.py
@@ -124,9 +124,15 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData,
lookupMib, future = cbCtx
if future.cancelled():
return
- future.set_result(
- (errorIndication, errorStatus, errorIndex, vbProcessor.unmakeVarBinds(snmpEngine, varBinds, lookupMib))
- )
+ try:
+ varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds,
+ lookupMib)
+ except Exception as e:
+ future.set_exception(e)
+ else:
+ future.set_result(
+ (errorIndication, errorStatus, errorIndex, varBindsUnmade)
+ )
notifyName = lcd.configure(
snmpEngine, authData, transportTarget, notifyType