diff options
author | Ilya Etingof <etingof@gmail.com> | 2016-11-05 22:59:31 +0100 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2016-11-05 22:59:31 +0100 |
commit | c54a3f6dc8ee433a55001e1cd97f6801bd6e52b7 (patch) | |
tree | 36b8477a686d5e15a8c6ab028626c69e7303eb10 /examples/hlapi | |
parent | a0ef4b6ce81683dc33ae00b3dcedd1c4ec282249 (diff) | |
download | pysnmp-git-asyncio-dispatcher-fixes.tar.gz |
WIP: gracefully shutdown asyncio dispatcherasyncio-dispatcher-fixes
Diffstat (limited to 'examples/hlapi')
5 files changed, 22 insertions, 15 deletions
diff --git a/examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py b/examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py index 92d3e70e..94926f55 100644 --- a/examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py @@ -27,6 +27,7 @@ from pysnmp.hlapi.asyncio import * @asyncio.coroutine def run(): snmpEngine = SnmpEngine() + errorIndication, errorStatus, errorIndex, varBinds = yield from sendNotification( snmpEngine, CommunityData('public', mpModel=0), @@ -44,7 +45,7 @@ def run(): if errorIndication: print(errorIndication) - snmpEngine.transportDispatcher.closeDispatcher() + yield from unconfigureNtfOrg(snmpEngine) asyncio.get_event_loop().run_until_complete(run()) diff --git a/examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py b/examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py index 027d3ac6..5345e98b 100644 --- a/examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py +++ b/examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py @@ -56,7 +56,12 @@ def sendone(snmpEngine, hostname, notifyType): snmpEngine = SnmpEngine() loop = asyncio.get_event_loop() + +# send notifications concurrently loop.run_until_complete( asyncio.wait([sendone(snmpEngine, 'demo.snmplabs.com', 'trap'), sendone(snmpEngine, 'demo.snmplabs.com', 'inform')]) ) + +# this will cancel internal timer +loop.run_until_complete(unconfigureNtfOrg(snmpEngine))
\ No newline at end of file diff --git a/examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py index b45057e3..e5f493c0 100644 --- a/examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py +++ b/examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py @@ -22,11 +22,9 @@ from pysnmp.hlapi.asyncio import * @asyncio.coroutine -def run(varBinds): - snmpEngine = SnmpEngine() +def run(snmpEngine, varBinds): while True: - errorIndication, errorStatus, errorIndex, \ - varBindTable = yield from bulkCmd( + errorIndication, errorStatus, errorIndex, varBindTable = yield from bulkCmd( snmpEngine, UsmUserData('usr-none-none'), UdpTransportTarget(('demo.snmplabs.com', 161)), @@ -38,11 +36,8 @@ def run(varBinds): print(errorIndication) break elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex) - 1][0] or '?' - ) - ) + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) else: for varBindRow in varBindTable: for varBind in varBindRow: @@ -52,10 +47,11 @@ def run(varBinds): if isEndOfMib(varBinds): break - snmpEngine.transportDispatcher.closeDispatcher() + yield from unconfigureCmdGen(snmpEngine) +snmpEngine = SnmpEngine() loop = asyncio.get_event_loop() loop.run_until_complete( - run([ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'))]) + run(snmpEngine, [ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'))]) ) diff --git a/examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-queries.py b/examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-queries.py index ad9c441b..b9de2660 100644 --- a/examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-queries.py +++ b/examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-queries.py @@ -47,8 +47,13 @@ def getone(snmpEngine, hostname): snmpEngine = SnmpEngine() loop = asyncio.get_event_loop() + +# run parallel queries loop.run_until_complete( asyncio.wait([getone(snmpEngine, ('demo.snmplabs.com', 1161)), getone(snmpEngine, ('demo.snmplabs.com', 2161)), getone(snmpEngine, ('demo.snmplabs.com', 3161))]) ) + +# unconfigure SNMP engine +loop.run_until_complete(unconfigureCmdGen(snmpEngine)) diff --git a/examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-queries.py b/examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-queries.py index 4a43bc49..b9416366 100644 --- a/examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-queries.py +++ b/examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-queries.py @@ -37,8 +37,8 @@ def getone(snmpEngine, hostname): print('%s at %s' % ( errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?' + ) ) - ) else: for varBind in varBinds: print(' = '.join([x.prettyPrint() for x in varBind])) @@ -48,11 +48,11 @@ def getone(snmpEngine, hostname): def getall(snmpEngine, hostnames): for hostname in hostnames: yield from getone(snmpEngine, hostname) - + yield from unconfigureCmdGen(snmpEngine) snmpEngine = SnmpEngine() loop = asyncio.get_event_loop() loop.run_until_complete(getall(snmpEngine, [('demo.snmplabs.com', 1161), ('demo.snmplabs.com', 2161), - ('demo.snmplabs.com', 3161)])) + ('demo.snmplabs.com', 3161)]))
\ No newline at end of file |