Skip to content

Instantly share code, notes, and snippets.

View joeblackwaslike's full-sized avatar
💭
Working hard

Joe Black joeblackwaslike

💭
Working hard
View GitHub Profile
"""
This script demonstrates the use of nested transactions in SQLAlchemy, including
a workaround for an issue with the SQLite backend.
References:
http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#using-savepoint
http://docs.sqlalchemy.org/en/latest/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl
"""
from sqlalchemy import Column, String, Integer
@joeblackwaslike
joeblackwaslike / run_coroutine_in_another_thread.py
Created February 12, 2022 23:17 — forked from lars-tiede/run_coroutine_in_another_thread.py
Safely run a coroutine in another thread's asyncio loop and return the result
import threading
import asyncio
async def run_coro_threadsafe(self, coro, other_loop, our_loop = None):
"""Schedules coro in other_loop, awaits until coro has run and returns
its result.
"""
loop = our_loop or asyncio.get_event_loop()
# schedule coro safely in other_loop, get a concurrent.future back