<div dir="ltr"><div><div><div><div>We recently started experiencing the following error: <b>RuntimeError: maximum recursion depth exceeded while calling a Python object</b><br><br></div>After a fair bit of debugging we eventually found the problem and implemented a fix for it in our codebase. We found that if a waiting<br>
</div>queue on a DeferredLock is ~125 (depending on call depth) the error can error. I recommend releasing the lock in a callLater.<br><br></div>The offending line is here: <a href="https://twistedmatrix.com/trac/browser/trunk/twisted/internet/defer.py#L1360">https://twistedmatrix.com/trac/browser/trunk/twisted/internet/defer.py#L1360</a><br>
</div>And the script below can be used to reproduce the issue.<br><div><div><div><div><div><br>#!/usr/bin/env python<br>from twisted.internet import defer, reactor<br><br>LOCK = defer.DeferredLock()<br>FIRST_RUN = True<br>
<br>def deferred_sleep(delay):<br> d = defer.Deferred()<br> delay = reactor.callLater(delay, d.callback, True)<br> d.delay = delay<br> return d<br><br>@defer.inlineCallbacks<br>def synchronized_call():<br> global FIRST_RUN<br>
yield LOCK.acquire()<br> try:<br> if FIRST_RUN:<br> FIRST_RUN = False<br> yield deferred_sleep(2)<br> print "Queue length: %s" % len(LOCK.waiting)<br> finally:<br>
LOCK.release()<br> #reactor.callLater(0, lambda: LOCK.release())<br><br><br>if __name__ == '__main__':<br> count = 125<br> def start_test():<br> for i in xrange(count):<br> synchronized_call()<br>
<br> reactor.callWhenRunning(start_test)<br> reactor.run()<br><br><div><a href="http://www.ml.sun.ac.za/" target="_blank"></a><div></div><div></div>
</div></div></div></div></div></div></div>