crate / crate-python

Python DB API client library for CrateDB, using HTTP.
https://cratedb.com/docs/python/
Apache License 2.0
79 stars 31 forks source link

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

Closed amotl closed 5 months ago

amotl commented 5 months ago

About

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

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

amotl commented 5 months ago

@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.