Comments (4)
Have you been able to figure out, with the memory_profiler
library, what objects are leaking?
Do you run your code in multiple threads?
So far I do not see obvious issues with your pysnmp code, however I have a few suggestions:
- switch to pysnmp hlapi followed by
SnmpEngine
instance unloading to free up resources - use a single persistent
SnmpEngine
instance for all your SNMP queries -- not only it would be more efficient, it might work around possible bugs causing memory leak
from pysnmp.
Can you please elaborate on this answer? How exactly would I do "SnmpEngine instance unloading to free up resources"? Do you just mean that I should call
del snmpEngine
after I use it? Or is it more involved than that?
Yes we run the code in multiple threads.
from pysnmp.
Let me revise my original answer then. Assuming you are calling SNMPGet
from a thread and you are not doing SNMP I/O asynchronously, my suggestion is to use something like this:
from pysnmp.hlapi import *
from pysnmp.hlapi.lcd import CommandGeneratorLcdConfigurator
class SNMPGet:
"""Instance of this class must be thread-local, not shared between threads."""
def __init__(self, *):
self._snmpEngine = SnmpEngine()
def _internal_execute(self, tmp_object_identifiers):
gen = getCmd(self._snmpEngine,
CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
*[ObjectType(ObjectIdentity(oid)) for oid in tmp_identifiers])
errorIndication, errorStatus, errorIndex, varBinds = next(gen)
def cleanup(self):
"""Running SnmpEngine instance against ever increasing set of targets may grow memory.
To drop SnmpEngine's caches you can periodically call this method. The backside is
slight drop in performance as hot caches will have to be repopulated.
"""
CommandGeneratorLcdConfigurator.unconfigure(self._snmpEngine)
As a side note, if you are fetching many OIDs from many targets, async I/O may give you better performance compared to MT one.
from pysnmp.
If the leak shows up with the later pysnmp versions -- please reopen this issue. Thank you!
from pysnmp.
Related Issues (20)
- Sporadic Timeout using set HOT 2
- <lambda>() takes 3 positional arguments but 4 were given HOT 5
- Project URL now redirects to Suspicious/Malware Site HOT 1
- Sending requests from specific interface not working.
- Get no result of getCmd HOT 4
- Attempted "__hash__" operation on ASN.1 schema object HOT 13
- pysnmp doesn't support IPv6 link-local addresses HOT 1
- Hello there, new to python and pysnmp. HOT 2
- AttributeError: 'UdpTransportTarget' object has no attribute 'contextName' HOT 2
- snmpget retry HOT 1
- Some authentication/privacy combinations are not working correctly? HOT 1
- .snmprec Generation HOT 1
- pysnmp usinng with SNMP V3 HOT 3
- Strange error when running the code given HOT 4
- Incomplete OID Retrieval: SNMP Walk (nextCmd/bulkCmd) Fails to Capture All OIDs HOT 6
- This project is dead please open issues with a fork HOT 1
- MibCompiler error when node name is 'as',the key world change to 'pysmi_as'
- Pysnmp HOT 1
- Python 3.12 compatibility - deprecated asyncore HOT 2
- Identical communities for read and write HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pysnmp.