Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure DB API interface attribute threadsafety = 1: Threads may share the module, but not connections #635

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

amotl
Copy link
Member

@amotl amotl commented Jun 26, 2024

About

Relating to the section about thread safety in PEP 0249 ...

  • The driver currently configures threadsafety = 2, which means "Threads may share the module and connections."
  • Now, it will configure threadsafety = 1, which means "Threads may share the module, but not connections."

Discussion

@hlcianfagna asked:

When using the python driver, is it ok to share a connection with multiple threads each opening their own cursor or should each thread have its own connection?

@amotl said:

Thread-per-connection sounds reasonable.

@mfussenegger said:

I think it currently relies on Python GIL, and afaik if you'd share a connection with the multiprocessing module across processes, things would break. So, it could be worth changing that to 1.

@hlcianfagna said:

I would say the same, should we document it?

References

/cc @hlcianfagna, @hammerhead, @surister, @proddata, @simonprickett

This signals "Threads may share the module, but not connections.",
according to PEP 0249.

-- https://peps.python.org/pep-0249/#threadsafety
@amotl amotl requested review from mfussenegger and matriv June 26, 2024 14:24
@amotl
Copy link
Member Author

amotl commented Jun 26, 2024

@hlcianfagna said:

I would say the same, should we document it?

Let me know if you think we should also add a dedicated section within the documentation. I think it could be worth it, if we don't refer to relevant thread safety details anywhere yet. I didn't check yet, though.

@amotl amotl requested a review from seut June 26, 2024 15:52
@amotl amotl merged commit a928d96 into master Jun 27, 2024
14 checks passed
@amotl amotl deleted the collab/threadsafety-level-1 branch June 27, 2024 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants