I’m attempting to implement a fairly basic async application using pysnmp-lextudio. Ideally I’d like to offer a command line that lets me send commands (get/set) as well as be notified of incoming trap/informs.
I think I’ve got the command line aspect down using code similar to:
async def interactive_prompt():
"""Provide a continuous prompt for user input."""
print("Enter 'help' for a list of commands.")
while True:
user_input = input("> ").strip()
await process_command(user_input)
async def main():
await asyncio.gather(
# receive_notifications(),
interactive_prompt()
)
if __name__ == "__main__":
asyncio.run(main())
However I’m struggling understanding how the various notification handling examples fit into this setup (if at all). An example provided here: https://docs.lextudio.com/pysnmp/examples/v1arch/asyncio/manager/ntfrcv/transport-tweaks seems as though it blocks at the following:
...
try:
# Dispatcher will never finish as job#1 never reaches zero
transportDispatcher.runDispatcher()
finally:
transportDispatcher.closeDispatcher()
Assuming that does block, my first inclination (coming from the world of c++) is that this needs to exist in a separate thread as it will never allow other tasks to run. I’m obviously fairly new to the world of async python – so perhaps I’m missing something obvious here. My attempts to poke around the code haven’t really turned up anything. I’d really appreciate some clarification on this one. Am I misguided in my embracing of asyncio? Should I follow my instinct and revert to using subprocess?