Search code examples
pythonmultiprocessingnet-snmp

ctypes netsnmp with multiprocessing


I was hoping someone could help...

so... i'm writing a multiprocessing based python netsnmp poller (i do a lot of data structure manipulation after i gather the data, so the overheads are worth it over normal threading). I couldn't find a complete python interface (with decent OID manipulation, bulkwalk etc.) so i decided to right my own ctypes bindings. i use snmp_sess_synch_response() to actually perform the query.

things work fine when i run a single thread (i can query and get results). but when i call my (python) netsnmp class from within an inherited Process instance; when it gets to snmp_sess_synch_response(), the thread just stalls and then returns with a return code of '2' and snmp_errstring() returns 'Unknown Error'.

the only information i could find is that i should be using the Single API from http://net-snmp.sourceforge.net/docs/README.thread.html and that the initial MIB build should be prior to threading. i am using the Single API and i am building the MIB before i spawn my workers.

does anyone have any idea how i should proceed to debug this? how is multithreading handled with ctypes? why would using multiprocessing cause my working single threaded poller to just stall like this?

i'm using net-snmp 5.5-41.el6 on redhat 6 64-bit and python 2.6.6.


Solution

  • this turned out to be an issue with not closing my filehandles, so after a while the thread had exhausted all of it's handles and prompted threw up a bunch of bad errors.