I can reasonably reliably reproduce this with loggerhead by firing it up and hitting it with ab -c, and it's not hard to see what happens in the code.
If two threads concurrently execute ScopeReplacer.__getattribute__ on the same instance, it's easy to see that one can execute _cleanup before the other enters _replace, and so the IllegalUseOfScopeReplacer condition gets hit.
In my case, simply not raising an exception in this situation would probably work, though I don't know if that would have any serious drawbacks (it looks to me like executing _import() twice won't have any real drawbacks, but it's not obvious).
I can reasonably reliably reproduce this with loggerhead by firing it up and hitting it with ab -c, and it's not hard to see what happens in the code.
If two threads concurrently execute ScopeReplacer. __getattribute_ _ on the same instance, it's easy to see that one can execute _cleanup before the other enters _replace, and so the IllegalUseOfSco peReplacer condition gets hit.
In my case, simply not raising an exception in this situation would probably work, though I don't know if that would have any serious drawbacks (it looks to me like executing _import() twice won't have any real drawbacks, but it's not obvious).