Is DB = Sequel.connect(...) threadsafe? #505

blambeau opened this Issue Jun 22, 2012 · 2 comments


None yet

2 participants


Hi Jeremy!

Quoting the doc:

"If you are only connecting to a single database, it is recommended that you store the database object in a constant named DB."

Can I safely assume that the DB instance can be used in a multithreaded environment? The doc says nothing about it so far. It would be nice to explain the idiomatic way to use Sequel with multiple threads somewhere.

Sorry if such info is already available and I simply missed it.


Well, if you are creating Database objects at run time (i.e. during normal operation, not just during application loading), you probably aren't going to want to assign it to a constant. To answer the question posed in the subject, the Sequel.connect(...) part is threadsafe, but assigning to a constant may not be.

Many people use Sequel in a multithreaded environment, but usually they don't need to create multiple Database objects. The Database object uses a thread-safe connection pool internally, so you don't need to create a separate Database object per thread, if that's what you are attempting to do.

There's a brief document on Sequel's thread safety that you may want to read:

In the future, please ask questions like this on the sequel-talk Google Group. The GitHub issue tracker is used for tracking bugs and pull requests, not for general support questions. Thanks!


Oops, sorry for using github issues. I'll use the google group in the future. Anyway, thanks, I've found the answer I was looking for; actually, in the source code, not in the document, but anyway ;-)

Thanks, and sorry again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment