title: Why does PyGame freeze when used in combination with PyMongo?
body: <p>What is this error, I have no idea what to do... (PyMongo).</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:/Users/aatif/Documents/Projects/Games with pygame/Space Invader/Game with DB.py&quot;, line 248, in &lt;module&gt;
      play()
    File &quot;C:/Users/aatif/Documents/Projects/Games with pygame/Space Invader/Game with DB.py&quot;, line 23, in play
      c.insert_one({'Score': 3})
    File &quot;C:\Users\aatif\PycharmProjects\pythonProject6\venv\lib\site-packages\pymongo\collection.py&quot;, line 698, in insert_one
      self._insert(document,
    File &quot;C:\Users\aatif\PycharmProjects\pythonProject6\venv\lib\site-packages\pymongo\collection.py&quot;, line 613, in _insert
      return self._insert_one(
    File &quot;C:\Users\aatif\PycharmProjects\pythonProject6\venv\lib\site-packages\pymongo\collection.py&quot;, line 602, in _insert_one
      self.__database.client._retryable_write(
    File &quot;C:\Users\aatif\PycharmProjects\pythonProject6\venv\lib\site-packages\pymongo\mongo_client.py&quot;, line 1497, in _retryable_write
      with self._tmp_session(session) as s:
    File &quot;C:\Users\aatif\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py&quot;, line 113, in __enter__
      return next(self.gen)
    File &quot;C:\Users\aatif\PycharmProjects\pythonProject6\venv\lib\site-packages\pymongo\mongo_client.py&quot;, line 1829, in _tmp_session
      s = self._ensure_session(session)
    File &quot;C:\Users\aatif\PycharmProjects\pythonProject6\venv\lib\site-packages\pymongo\mongo_client.py&quot;, line 1816, in _ensure_session
      return self.__start_session(True, causal_consistency=False)
    File &quot;C:\Users\aatif\PycharmProjects\pythonProject6\venv\lib\site-packages\pymongo\mongo_client.py&quot;, line 1766, in __start_session
      server_session = self._get_server_session()
    File &quot;C:\Users\aatif\PycharmProjects\pythonProject6\venv\lib\site-packages\pymongo\mongo_client.py&quot;, line 1802, in _get_server_session
      return self._topology.get_server_session()
    File &quot;C:\Users\aatif\PycharmProjects\pythonProject6\venv\lib\site-packages\pymongo\topology.py&quot;, line 490, in get_server_session
      self._select_servers_loop(
    File &quot;C:\Users\aatif\PycharmProjects\pythonProject6\venv\lib\site-packages\pymongo\topology.py&quot;, line 215, in _select_servers_loop
      raise ServerSelectionTimeoutError(
  pymongo.errors.ServerSelectionTimeoutError: connection closed,connection closed,connection closed, Timeout: 30s, Topology Description: &lt;TopologyDescription id: 600999bd9735fa26e13f796f, topology_type: ReplicaSetNoPrimary, servers: [&lt;ServerDescription ('firstproject-shard-00-00.wy4pd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')&gt;, &lt;ServerDescription ('firstproject-shard-00-01.wy4pd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')&gt;, &lt;ServerDescription ('firstproject-shard-00-02.wy4pd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')&gt;]&gt;
  </code></pre>
  <p>Is my server offline or did I do something wrong setting up?
  Here is an example (very shortened but same problem occurs)</p>
  <pre class="lang-py prettyprint-override"><code>import pygame
  from pymongo import MongoClient
  # Eisa -&gt; Username, LolLol65 -&gt; Password
  pygame.init()
  win = pygame.display.set_mode((1000, 400))
  run = True
  cluster = MongoClient(
      'mongodb+srv://USER:PASSWORD@firstproject.wy4pd.mongodb.net/Calculator?retryWrites=true&amp;w=majority')
  db = cluster['Game']
  c = db['Scores']
  score = 0
  while run:
      score += 1
      win.fill((0, 0, 0))
      for e in pygame.event.get():
          if e.type == pygame.QUIT:
              run = False
          if e.type == pygame.KEYDOWN:
              c.insert_one({'Score': score})
      pygame.display.update()
  </code></pre>
  <p>(I added the code due to a comment asking me to. This code reproduces the same problem but i could also add the full code if it is better)</p>