annotate blender/asyncio_thread.py @ 2453:b23afde50bc2

blender addons get thier own pdm setup for now. fix time_from_graph startup race
author drewp@bigasterisk.com
date Sun, 18 May 2025 20:08:35 -0700
parents src/light9/blender/asyncio_thread.py@b8a408caf115
children 405abed9a45c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2432
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
1 import asyncio
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
2 from threading import Thread
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
3 from typing import Coroutine
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
4
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
5
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
6 def startLoopInThread(task: Coroutine) -> asyncio.AbstractEventLoop:
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
7
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
8 def start_background_loop(loop: asyncio.AbstractEventLoop) -> None:
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
9 asyncio.set_event_loop(loop)
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
10 loop.run_forever()
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
11
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
12 loop = asyncio.new_event_loop()
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
13 t = Thread(target=start_background_loop, args=(loop,), daemon=True)
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
14 t.start()
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
15 asyncio.run_coroutine_threadsafe(task, loop)
b8a408caf115 start blender sync
drewp@bigasterisk.com
parents:
diff changeset
16 return loop