x42005e1f commented on issue #50185: URL: https://github.com/apache/airflow/issues/50185#issuecomment-2912414727
Also note that the different APIs that aiologic provides should not be mixed in the same thread if threading is used for the green (sync) API. This is a fundamental problem due to the fact that primitives work at the task level: `lock.green_acquire()` can block the event loop when `aiologic.lowlevel.current_green_library() == "threading"`, and as a result lock will never be released. This is well demonstrated in the following example: <details> <summary>example.py</summary> ```python import asyncio import time import aiologic async def main(): lock = aiologic.Lock() async def a(): async with lock: print("before") await asyncio.sleep(0) print("after") # will never be printed! async def b(): with lock: time.sleep(0) await asyncio.gather(a(), b()) if __name__ == "__main__": asyncio.run(main()) ``` </details> This is the same as using `threading.Lock` along with asyncio tasks. If you have such calls somewhere, it can be the cause of deadlocks. This problem of mixing two APIs in the same thread can be solved by using [GLock](https://gist.github.com/x42005e1f/a50d0744013b7bbbd7ded608d6a3845b), which can be a thread-level lock - if you use the read-preferring readers-writer locks condition, its APIs can safely mix. However, since it would no longer be a task level, it would not be coroutine-safe. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org