{"action":"closed","issue":{"url":"https://api.github.com/repos/etingof/pysnmp/issues/160","repository_url":"https://api.github.com/repos/etingof/pysnmp","labels_url":"https://api.github.com/repos/etingof/pysnmp/issues/160/labels{/name}","comments_url":"https://api.github.com/repos/etingof/pysnmp/issues/160/comments","events_url":"https://api.github.com/repos/etingof/pysnmp/issues/160/events","html_url":"https://github.com/etingof/pysnmp/issues/160","id":335797383,"node_id":"MDU6SXNzdWUzMzU3OTczODM=","number":160,"title":"Trying to use nextCmd with asyncio, infinite loop over first element","user":{"login":"Djailla","id":576608,"node_id":"MDQ6VXNlcjU3NjYwOA==","avatar_url":"https://avatars2.githubusercontent.com/u/576608?v=4","gravatar_id":"","url":"https://api.github.com/users/Djailla","html_url":"https://github.com/Djailla","followers_url":"https://api.github.com/users/Djailla/followers","following_url":"https://api.github.com/users/Djailla/following{/other_user}","gists_url":"https://api.github.com/users/Djailla/gists{/gist_id}","starred_url":"https://api.github.com/users/Djailla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Djailla/subscriptions","organizations_url":"https://api.github.com/users/Djailla/orgs","repos_url":"https://api.github.com/users/Djailla/repos","events_url":"https://api.github.com/users/Djailla/events{/privacy}","received_events_url":"https://api.github.com/users/Djailla/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-06-26T12:31:38Z","updated_at":"2018-07-03T07:29:05Z","closed_at":"2018-07-03T07:29:05Z","author_association":"NONE","body":"Here is the code I try to use. My goal is to use asyncio/pysnmp to poll Raritan PDU probes. As the number of probes is unknown, I need to walk over elements. No issues with synchronous method. But with async, I kept receiving the first item.\r\n\r\nAny idea ?\r\n\r\n    import logging\r\n    import asyncio\r\n\r\n    from pysnmp.entity.rfc3413.oneliner import cmdgen\r\n    from pysnmp.hlapi.asyncio import (\r\n        nextCmd,\r\n        CommunityData,\r\n        UdpTransportTarget,\r\n        SnmpEngine,\r\n        ContextData,\r\n        ObjectIdentity,\r\n        ObjectType,\r\n    )\r\n    from pysnmp.error import PySnmpError\r\n\r\n    LOGGER = logging.getLogger(__name__)\r\n\r\n    HOSTNAME = 'xxxxxxxxxxx'\r\n    OIDS = [\r\n        '1.3.6.1.4.1.13742.6.3.6.3.1.3',\r\n        '1.3.6.1.4.1.13742.6.5.5.3.1.4.1',\r\n        '1.3.6.1.4.1.13742.6.3.6.3.1.2.1',\r\n    ]\r\n\r\n    def snmp_requests(host, *oids):\r\n        \"\"\"Query SNMP oids.\"\"\"\r\n        cmd_gen = cmdgen.CommandGenerator()\r\n        try:\r\n            error_indication, error_status, error_index, varbind_table = (\r\n                cmd_gen.nextCmd(\r\n                    cmdgen.CommunityData('public'),\r\n                    cmdgen.UdpTransportTarget((host, 161)),\r\n                    *oids\r\n                )\r\n            )\r\n\r\n        except PySnmpError as exc:\r\n            logging.warning(exc)\r\n            return None\r\n\r\n        if error_indication:\r\n            logging.warning('%s with this asset: %s', error_indication, host)\r\n\r\n        elif error_status:\r\n            logging.warning(\r\n                '%s at %s',\r\n                error_status.prettyPrint(),\r\n                error_index and varbind_table[-1][int(error_index) - 1] or '?'\r\n            )\r\n\r\n        else:\r\n            print(varbind_table)\r\n\r\n\r\n    async def async_next_snmp_request(host, *oids):\r\n        \"\"\"Walk SNMP oids asynchronously.\"\"\"\r\n        oid_values = [ObjectType(ObjectIdentity(oid)) for oid in oids]\r\n        while True:\r\n            try:\r\n                error_indication, error_status, error_index, varbind_table = (\r\n                    await nextCmd(\r\n                        SnmpEngine(),\r\n                        CommunityData('public', mpModel=0),\r\n                        UdpTransportTarget((host, 161)),\r\n                        ContextData(),\r\n                        *oid_values,\r\n                    )\r\n                )\r\n            except PySnmpError:\r\n                LOGGER.exception(\"PySNMP error\")\r\n                return\r\n\r\n            if error_indication:\r\n                LOGGER.warning('%s with this asset: %s', error_indication, host)\r\n                return\r\n\r\n            elif error_status:\r\n                LOGGER.warning(\r\n                    '%s at %s',\r\n                    error_status.prettyPrint(),\r\n                    error_index and varbind_table[-1][int(error_index) - 1] or '?'\r\n                )\r\n                return\r\n\r\n            else:\r\n                print(varbind_table)\r\n                yield varbind_table\r\n\r\n\r\n    async def async_snmp_walk(host, *oids):\r\n        async for varbind in async_next_snmp_request(host, *oids):\r\n            print(varbind)\r\n\r\n\r\n    def test_async():\r\n        loop = asyncio.get_event_loop()\r\n        tasks = [\r\n            loop.create_task(\r\n                async_snmp_walk(HOSTNAME, *OIDS)\r\n            )\r\n        ]\r\n\r\n        result = loop.run_until_complete(\r\n            asyncio.wait(\r\n                tasks,\r\n                loop=loop,\r\n            )\r\n        )\r\n        return result\r\n\r\n    print('SYNC')\r\n    snmp_requests(HOSTNAME, *OIDS)\r\n    print('------------------------')\r\n    print('ASYNC')\r\n    test_async()\r\n\r\nOutput :\r\n\r\n    SYNC\r\n    [[ObjectType(ObjectIdentity(<ObjectName value object at 0x10392a358 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.3.1.1]>), <OctetString value object at 0x10392a438 tagSet <TagSet object at 0x102f14a90 tags 0:0:4> subtypeSpec <ConstraintsIntersection object at 0x102f4d5f8 consts <ValueSizeConstraint object at 0x102f4d5c0 consts 0, 65535>> encoding iso-8859-1 payload [AEI7300505]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x10392a518 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.5.5.3.1.4.1.1]>), <Integer value object at 0x10392a5c0 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [234]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x10392a668 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.2.1.1]>), <Integer value object at 0x10392a748 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [10]>)], [ObjectType(ObjectIdentity(<ObjectName value object at 0x10392a630 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.3.1.2]>), <OctetString value object at 0x10392a1d0 tagSet <TagSet object at 0x102f14a90 tags 0:0:4> subtypeSpec <ConstraintsIntersection object at 0x102f4d5f8 consts <ValueSizeConstraint object at 0x102f4d5c0 consts 0, 65535>> encoding iso-8859-1 payload [AEI7300505]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x10393b588 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.5.5.3.1.4.1.2]>), <Integer value object at 0x10393b5c0 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [36]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x10393b5f8 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.2.1.2]>), <Integer value object at 0x10393b710 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [11]>)], [ObjectType(ObjectIdentity(<ObjectName value object at 0x10392a6a0 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.3.1.3]>), <OctetString value object at 0x103aa5dd8 tagSet <TagSet object at 0x102f14a90 tags 0:0:4> subtypeSpec <ConstraintsIntersection object at 0x102f4d5f8 consts <ValueSizeConstraint object at 0x102f4d5c0 consts 0, 65535>> encoding iso-8859-1 payload [AEI7300506]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x10393b470 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.5.5.3.1.4.1.3]>), <Integer value object at 0x10393b898 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [222]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x10393ba58 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.2.1.3]>), <Integer value object at 0x10393bb38 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [10]>)], [ObjectType(ObjectIdentity(<ObjectName value object at 0x103aa4978 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.3.1.4]>), <OctetString value object at 0x10393b4a8 tagSet <TagSet object at 0x102f14a90 tags 0:0:4> subtypeSpec <ConstraintsIntersection object at 0x102f4d5f8 consts <ValueSizeConstraint object at 0x102f4d5c0 consts 0, 65535>> encoding iso-8859-1 payload [AEI7300506]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x10393bac8 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.5.5.3.1.4.1.4]>), <Integer value object at 0x10393bc88 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [41]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x10393be48 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.2.1.4]>), <Integer value object at 0x10393bf28 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [11]>)]]\r\n    ------------------------\r\n    ASYNC\r\n    [[ObjectType(ObjectIdentity(<ObjectName value object at 0x103c98278 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.3.1.1]>), <OctetString value object at 0x103c49400 tagSet <TagSet object at 0x102f14a90 tags 0:0:4> subtypeSpec <ConstraintsIntersection object at 0x102f4d5f8 consts <ValueSizeConstraint object at 0x102f4d5c0 consts 0, 65535>> encoding iso-8859-1 payload [AEI7300505]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x103c98400 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.5.5.3.1.4.1.1]>), <Integer32 value object at 0x103c98160 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [234]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x103c98518 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.2.1.1]>), <Integer32 value object at 0x103c985f8 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [10]>)]]\r\n    [[ObjectType(ObjectIdentity(<ObjectName value object at 0x103c98278 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.3.1.1]>), <OctetString value object at 0x103c49400 tagSet <TagSet object at 0x102f14a90 tags 0:0:4> subtypeSpec <ConstraintsIntersection object at 0x102f4d5f8 consts <ValueSizeConstraint object at 0x102f4d5c0 consts 0, 65535>> encoding iso-8859-1 payload [AEI7300505]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x103c98400 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.5.5.3.1.4.1.1]>), <Integer32 value object at 0x103c98160 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [234]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x103c98518 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.2.1.1]>), <Integer32 value object at 0x103c985f8 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [10]>)]]\r\n    [[ObjectType(ObjectIdentity(<ObjectName value object at 0x103fa52e8 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.3.1.1]>), <OctetString value object at 0x103c9f2b0 tagSet <TagSet object at 0x102f14a90 tags 0:0:4> subtypeSpec <ConstraintsIntersection object at 0x102f4d5f8 consts <ValueSizeConstraint object at 0x102f4d5c0 consts 0, 65535>> encoding iso-8859-1 payload [AEI7300505]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x103fa5470 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.5.5.3.1.4.1.1]>), <Integer32 value object at 0x103fa51d0 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [235]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x103fa5588 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.2.1.1]>), <Integer32 value object at 0x103fa5668 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [10]>)]]\r\n    [[ObjectType(ObjectIdentity(<ObjectName value object at 0x103fa52e8 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.3.1.1]>), <OctetString value object at 0x103c9f2b0 tagSet <TagSet object at 0x102f14a90 tags 0:0:4> subtypeSpec <ConstraintsIntersection object at 0x102f4d5f8 consts <ValueSizeConstraint object at 0x102f4d5c0 consts 0, 65535>> encoding iso-8859-1 payload [AEI7300505]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x103fa5470 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.5.5.3.1.4.1.1]>), <Integer32 value object at 0x103fa51d0 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [235]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x103fa5588 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.2.1.1]>), <Integer32 value object at 0x103fa5668 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [10]>)]]\r\n    [[ObjectType(ObjectIdentity(<ObjectName value object at 0x1040f1080 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.3.1.1]>), <OctetString value object at 0x103f01f98 tagSet <TagSet object at 0x102f14a90 tags 0:0:4> subtypeSpec <ConstraintsIntersection object at 0x102f4d5f8 consts <ValueSizeConstraint object at 0x102f4d5c0 consts 0, 65535>> encoding iso-8859-1 payload [AEI7300505]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x1040f1208 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.5.5.3.1.4.1.1]>), <Integer32 value object at 0x103f01ef0 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [235]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x1040f1320 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.2.1.1]>), <Integer32 value object at 0x1040f1400 tagSet <TagSet object at 0x102ec0c50 tags 0:0:2> subtypeSpec <ConstraintsIntersection object at 0x102e92e48 consts <ValueRangeConstraint object at 0x102e92e10 consts -2147483648, 2147483647>> payload [10]>)]]\r\n    [[ObjectType(ObjectIdentity(<ObjectName value object at 0x1040f1080 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.3.6.3.1.3.1.1]>), <OctetString value object at 0x103f01f98 tagSet <TagSet object at 0x102f14a90 tags 0:0:4> subtypeSpec <ConstraintsIntersection object at 0x102f4d5f8 consts <ValueSizeConstraint object at 0x102f4d5c0 consts 0, 65535>> encoding iso-8859-1 payload [AEI7300505]>), ObjectType(ObjectIdentity(<ObjectName value object at 0x1040f1208 tagSet <TagSet object at 0x102f14ef0 tags 0:0:6> payload [1.3.6.1.4.1.1374....6.5.5.3.1.4.1.1]"}}
{"actor":{"display_login":"Djailla"}}