From a8b439dbdd01f73f4bb47dd0991b696d38021458 Mon Sep 17 00:00:00 2001
From: Lex Li <support@lextm.com>
Date: Sat, 10 Feb 2024 22:30:34 -0500
Subject: [PATCH] Fixed a dispatch bug.

---
 pysnmp/carrier/asyncio/dispatch.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/pysnmp/carrier/asyncio/dispatch.py b/pysnmp/carrier/asyncio/dispatch.py
index a97282462..d0c1b0314 100644
--- a/pysnmp/carrier/asyncio/dispatch.py
+++ b/pysnmp/carrier/asyncio/dispatch.py
@@ -63,15 +63,16 @@ def runDispatcher(self, timeout=0.0):
         if not self.loop.is_running():
             try:
                 if timeout > 0:
-                    self.loop.call_later(timeout, self.closeDispatcher)
+                    self.loop.call_later(timeout, self.__closeDispatcher)
                 self.loop.run_forever()
             except KeyboardInterrupt:
                 raise
             except Exception:
                 raise PySnmpError(';'.join(traceback.format_exception(*sys.exc_info())))
-    
-    def closeDispatcher(self):
-        self.loop.stop()
+
+    def __closeDispatcher(self):
+        if self.loop.is_running():
+            self.loop.stop()
         super().closeDispatcher()
 
     def registerTransport(self, tDomain, transport):