I want to create a thread which performs an SNMP walk, but the main thread
blocks on the pending request too.

I attach the source code of the test i wrote.

The main thread prints on standard output every second.
A second thread performs a walk.
The main threads blocks until the snmp walk is finished

Is it a bug?

How can avoid this problem? Is this a problem of the python bindings or 
what else?

Thank you very much.


TRY
===

$ python netsnmp_thread.py    <your host>    1.3.6.1.2.1.1.1



SOURCE CODE
==========


import time,sys
import netsnmp
import threading


if len(sys.argv) != 3:
    print "Usage: python %s <host> <oid>" % (sys.argv[0])
    sys.exit(-1)
   
host = sys.argv[1]
   
oid_table  = sys.argv[2]

TIMEOUT=1000000
RETRIES=10


class TestThread(threading.Thread):
   
    def __init__(self, oid):
        super(TestThread, self).__init__()   
        self.oid = oid
       
    def run(self):
        print "THREAD: start"
       
        start = time.time()
        var = netsnmp.Varbind( '.' + self.oid )
        varlist = netsnmp.VarList( var )
        t = netsnmp.snmpwalk( varlist , Version=1, DestHost=host,
                              Community='public', 
Version=2,                                   
                              UseNumeric=1,
                              Timeout=TIMEOUT, Retries=RETRIES)
       
        end = time.time()
       
        print "THREAD: request time %s" % (end-start)
        if t != None:
            for a in varlist:
                print '%s.%s = %s (%s, %s)' % (a.tag, str(a.iid), 
str(a.val), str(a.type), type(a.val))
            else:
                print "no result"
    print "THREAD: finish!"


t = TestThread(oid_table)

last = time.time()
print "main thread..."

t.start()

while True:
    now = time.time()
    print "main thread going idle...elapsed=%s" % (now-last)
    last = now
    time.sleep(1.0)


------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to