MCPcopy
hub / github.com/tortoise/tortoise-orm / run_async

Function run_async

tortoise/__init__.py:555–585  ·  view source on GitHub ↗

Simple async runner that cleans up DB connections on exit. This is meant for simple scripts. Usage:: from tortoise import Tortoise, run_async async def do_stuff(): await Tortoise.init( db_url='sqlite://db.sqlite3', models={'

(coro: Coroutine)

Source from the content-addressed store, hash-verified

553
554
555def run_async(coro: Coroutine) -> None:
556 """
557 Simple async runner that cleans up DB connections on exit.
558 This is meant for simple scripts.
559
560 Usage::
561
562 from tortoise import Tortoise, run_async
563
564 async def do_stuff():
565 await Tortoise.init(
566 db_url='sqlite://db.sqlite3',
567 models={'models': ['app.models']}
568 )
569
570 ...
571
572 run_async(do_stuff())
573 """
574 from tortoise.context import get_current_context
575
576 async def main() -> None:
577 try:
578 await coro
579 finally:
580 ctx = get_current_context()
581 if ctx is not None:
582 await ctx.connections.close_all(discard=True)
583
584 with from_thread.start_blocking_portal() as portal:
585 portal.call(main)
586
587
588__version__ = "1.1.7"

Callers 15

test_run_asyncFunction · 0.90
test_run_async_raisedFunction · 0.90
signals.pyFile · 0.90
two_databases.pyFile · 0.90
transactions.pyFile · 0.90
group_by.pyFile · 0.90
relations.pyFile · 0.90
schema_create.pyFile · 0.90
postgres.pyFile · 0.90

Calls

no outgoing calls

Tested by 2

test_run_asyncFunction · 0.72
test_run_async_raisedFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…