Skip to content

Commit 4ea9405

Browse files
committed
add method num_queued_traps
1 parent 3ab7efa commit 4ea9405

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

netsnmpagent.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,12 +929,15 @@ def shutdown(self):
929929
# one effectively has to rely on the OS to release resources.
930930
# libnsa.shutdown_agent()
931931

932+
def num_queued_traps(self):
933+
return len(self.queued_traps)
934+
932935
def queue_trap(self, *args, **kwargs):
933936
'''This method queues a trap to be sent from the main thread loop.
934-
In SNMP v5.7.3 (and likely others), many traps sent from threads in agentx
935-
sub-agents are duplicated. This method and send_queued_traps() support
936-
queueing traps in non-main threads and actually sending them from the
937-
main thread in the "check_and_process loop."
937+
In SNMP v5.7.3 (and likely other version), many traps sent from threads
938+
in agentx sub-agents are duplicated. This method and send_queued_traps()
939+
support queueing traps in non-main threads and actually sending them from
940+
the main thread in the "check_and_process loop."
938941
'''
939942
with self.trap_lock:
940943
self.queued_traps.append((args, kwargs))
@@ -943,6 +946,8 @@ def send_queued_traps(self):
943946
'''This method must be called from the main thread loop and dequeues and
944947
send all queued traps.
945948
'''
949+
if not len(self.queued_traps):
950+
return
946951
with self.trap_lock:
947952
for arg_tuple in self.queued_traps:
948953
(args, kwargs) = arg_tuple

0 commit comments

Comments
 (0)