diff options
author | Rob Austein <sra@hactrn.net> | 2009-07-29 09:28:42 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2009-07-29 09:28:42 +0000 |
commit | 118bc24016e7090bb1789da874a77cba50e1ce8a (patch) | |
tree | 86349b685d8727bf2a8f458eecf5f91d75e6996c | |
parent | 28a6bae598a985d2dbc0b33e2d996bed6aefbf87 (diff) |
Extend rpki.async.iterator to support unwinding the stack to avoid
recursion limit when processing really long iterations.
svn path=/rpkid/rpki/async.py; revision=2678
-rw-r--r-- | rpkid/rpki/async.py | 21 | ||||
-rw-r--r-- | rpkid/rpki/left_right.py | 2 |
2 files changed, 12 insertions, 11 deletions
diff --git a/rpkid/rpki/async.py b/rpkid/rpki/async.py index c7cd61b7..7248e860 100644 --- a/rpkid/rpki/async.py +++ b/rpkid/rpki/async.py @@ -42,11 +42,11 @@ class iterator(object): The termination callback receives no arguments. """ - def __init__(self, iterable, item_callback, done_callback): + def __init__(self, iterable, item_callback, done_callback, unwind_stack = False): self.item_callback = item_callback self.done_callback = done_callback self.caller_file, self.caller_line, self.caller_function = traceback.extract_stack(limit = 2)[0][0:3] - #rpki.log.debug("Created iterator id %s file %s line %s function %s" % (id(self), self.caller_file, self.caller_line, self.caller_function)) + self.timer = timer(handler = item_callback) if unwind_stack else None try: self.iterator = iter(iterable) except (ExitNow, SystemExit): @@ -57,14 +57,15 @@ class iterator(object): self() def __repr__(self): - return "<asynciterator created at %s:%d %s at 0x%x>" % (self.caller_file, self.caller_line, self.caller_function, id(self)) - - def __call__(self, *args): - if args != (): - rpki.log.warn("Arguments passed to %r: %r" % (self, args)) - for x in traceback.format_stack(): - rpki.log.warn(x.strip()) - assert args == () + return "<%s created at %s:%d %s at 0x%x>" % (self.__class__.__name__, self.caller_file, self.caller_line, self.caller_function, id(self)) + + def __call__(self): + if self.timer is None: + self.doit() + else: + self.timer.set(None) + + def doit(self): try: self.item_callback(self, self.iterator.next()) except StopIteration: diff --git a/rpkid/rpki/left_right.py b/rpkid/rpki/left_right.py index a2c1b01f..3ee75a33 100644 --- a/rpkid/rpki/left_right.py +++ b/rpkid/rpki/left_right.py @@ -917,7 +917,7 @@ class msg(rpki.xml_utils.msg, left_right_namespace): def done(): cb(r_msg) - rpki.async.iterator(self, loop, done) + rpki.async.iterator(self, loop, done, unwind_stack = True) class sax_handler(rpki.xml_utils.sax_handler): """ |