Skip to content

Instantly share code, notes, and snippets.

@alksndrglk
Created January 15, 2024 06:31
Show Gist options
  • Select an option

  • Save alksndrglk/c29056a5f0651fd562feef7fe3c05aae to your computer and use it in GitHub Desktop.

Select an option

Save alksndrglk/c29056a5f0651fd562feef7fe3c05aae to your computer and use it in GitHub Desktop.
session in thread
transmission = sessionmaker(db_transmission1c)
class Handler(Thread):
def __init__(self, q):
Thread.__init__(self)
self.q: Queue = q
def run(self):
def process(session):
'''some important work'''
while self.q.not_empty:
content_id = self.q.get()
try:
with transmission.begin() as sessio:
process(session)
except (OperationalError, DatabaseError):
logger.critical('UNDEFINED ERR: ', exc_info=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment