def listen(self, _community, callback): """Listens for and dispatches incoming traps to callback. Any exceptions that occur, except SystemExit, are logged and subsequently ignored to avoid taking down the entire snmptrapd process by accident. """ self._client_callback = callback while 1: fdlist, timeout = netsnmp.snmp_select_info() try: rlist, _wlist, _xlist = select.select(fdlist, [], [], timeout) except select.error as error: if error.args[0] == EINTR: continue else: raise if rlist: for fdescr in rlist: netsnmp.snmp_read(fdescr) else: netsnmp.lib.snmp_timeout()