Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:26:57+00:00 2026-06-05T13:26:57+00:00

I know pymongo is thread safe and has an inbuilt connection pool. In a

  • 0

I know pymongo is thread safe and has an inbuilt connection pool.

In a web app that I am working on, I am creating a new connection instance on every request.

My understanding is that since pymongo manages the connection pool, it isn’t wrong approach to create a new connection on each request, as at the end of the request the connection instance will be reclaimed and will be available on subsequent requests.

Am I correct here, or should I just create a single instance to use across multiple requests?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:26:59+00:00Added an answer on June 5, 2026 at 1:26 pm

    The “wrong approach” depends upon the architecture of your application. With pymongo being thread-safe and automatic connection pooling, the actual use of a single shared connection, or multiple connections, is going to “work”. But the results will depend on what you expect the behavior to be. The documentation comments on both cases.

    If your application is threaded, from the docs, each thread accessing a connection will get its own socket. So whether you create a single shared connection, or request a new one, it comes down to whether your requests are threaded or not.

    When using gevent, you can have a socket per greenlet. This means you don’t have to have a true thread per request. The requests can be async, and still get their own socket.

    In a nutshell:

    • If your webapp requests are threaded, then it doesn’t matter which way you access a new connection. The result will be the same (socket per thread)
    • If your webapp is async via gevent, then it doesn’t matter which way you access a new conection. The result will be the same. (socket per greenlet)
    • If your webapp is async, but NOT via gevent, then you have to take into consideration the notes on the best suggested workflow.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that I can use ProxyPass to serve up my yardoc server instance
I know that I can do something like $int = (int)99; //(int) has a
I'm working on creating scripts using python, mongodb and the pymongo module to fetch
I know this is something that has been discussed over and over, and I
I know that a fragment's view hierarchy has to be inflated in onCreateView, but
I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
I know that it's a subject that can raise a lot of debate, but
I know this question has kind-a started religious wars in past and there might
I know that one of the differences between classes and structs is that struct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.