-
-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Description
It seems lazy-object-proxy is not threadsafe. If you look at the following example you will see the doit
invoked multiple times in some runs of the script. For my use-cases it needs a threadsafe version of this, as the object being created is at module-scope and threadsafe itself (re.compile
). It's not a big deal in some scenarios that 2 copies are created but it's not great and quite subtle when moving to this lazy-creation versus immediate creation when refactoring to use this library. Thoughts?
from lazy_object_proxy import Proxy
import threading
x = 0
def doit():
global x
x += 1
print('doing it', x)
return x
p = Proxy(doit)
def work(obj):
print(obj)
threading.Thread(None, target=work, args=(p,)).start()
threading.Thread(None, target=work, args=(p,)).start()
output:
loop 0
doing it 1
1
doing it 2 <-- doit invoked again for the same proxy
2
expected:
loop 0
doing 1
1
1
SF-300
Metadata
Metadata
Assignees
Labels
No labels