python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

Review thread safety of client/API/Evaluation context

Open toddbaert opened this issue 2 years ago • 3 comments

Review the thread safety of the SDK to make sure there's no potential concurrency issues, particularly around state maintained in the global API object, clients, and evaluation context objects.

See here for a similar discussion in the Java SDK and others.

Definition of done:

  • [ ] issues created for thread safety of global API, client, and evaluation context.

toddbaert avatar Apr 18 '23 13:04 toddbaert

@matthewelwell @hlipsig @tcarrio do we need to worry about locking/concurrency here? I know there's a threading module in Python. Are any locks necessary, especially around global state? From our meeting if sounds like this might not be necessary, but I have limited Python experience and can't say...

toddbaert avatar Apr 19 '23 11:04 toddbaert

Hey @federicobond perhaps you could answer this question. Do we need to be concerned about threading issues?

beeme1mr avatar Oct 18 '23 21:10 beeme1mr

I'd have to take a closer look at it. The GIL has us covered in some cases for simple assignments but anything more complex than that should probably be guarded by a lock.

add_hooks is probably not thread-safe due to read-update-write race conditions when concatenating lists.

set_provider used to be thread safe but likely isn't now with the new shutdown and initialize logic.

federicobond avatar Oct 18 '23 23:10 federicobond