Detect multiple calls to a Traits default constructor.
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
When using Traits in a multithreaded environment, one of the (many) possible things that can go wrong is accidentally invoking a Traits default constructor simultaneously from more than one thread. That's usually an error in the application code rather than in Traits itself; nevertheless, it would be nice if there were some way to easily detect and warn about this situation.
It's not clear to me right now whether there's a cheap solution to this. It's critical that any solution doesn't slow down traits attribute access in general, though I imagine a small performance hit to the default constructor would be acceptable.
Here's some code that demonstrates the issue:
```
import threading
from traits.api import HasTraits, List
class A(HasTraits):
cheeses = List
def add_new_item(self, event):
event.wait()
self.cheeses.append("gorgonzola")
for _ in xrange(1000):
a = A()
event = threading.Event()
t = threading.Thread(target=a.add_new_item, args=(event,))
t.start()
event.set()
a.cheeses.append("brie")
t.join()
assert len(a.cheeses) == 2 # Will occasionally fail.
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.