code: def test_lookup_threadsafe(self):
      # Increase if it does not fail with KeyError
      MAX_CYCLES = 2000
  
      errs = []
  
      def f(pg_code="40001"):
          try:
              errorcodes.lookup(pg_code)
          except Exception as e:
              errs.append(e)
  
      for __ in range(MAX_CYCLES):
          reload(errorcodes)
          (t1, t2) = (Thread(target=f), Thread(target=f))
          (t1.start(), t2.start())
          (t1.join(), t2.join())
  
          if errs:
              self.fail(
                  "raised {} errors in {} cycles (first is {} {})".format(
                      len(errs),
                      MAX_CYCLES,
                      errs[0].__class__.__name__,
                      errs[0],
                  )
              )
  
file_path: psycopg2/tests/test_errcodes.py
imports: import unittest
  from .testutils import ConnectingTestCase, slow, reload
  from threading import Thread
  from psycopg2 import errorcodes
label_desc: Use image node_id 1 for calling the ErrocodeTests obj's underlying member method code with example usage: obj.test_lookup_threadsafe() without return types