dabla commented on code in PR #73560:
URL: https://github.com/apache/airflow/pull/73560#discussion_r4103963181


##########
task-sdk/src/airflow/sdk/bases/operator.py:
##########
@@ -200,25 +200,50 @@ def coerce_resources(resources: dict[str, Any] | None) -> 
Resources | None:
     return Resources(**resources)
 
 
+def _thread_event_loop() -> AbstractEventLoop | None:
+    """
+    Return the event loop set for the current thread, if any, without creating 
one.
+
+    ``asyncio.get_event_loop()`` creates (and since Python 3.12 warns about, 
since 3.14 refuses) a loop
+    when none is set, so the policy's per-thread state is inspected instead.  
Event loop policies are
+    deprecated in Python 3.14, hence the guards: without one, no loop is 
reported and the caller creates
+    its own.
+    """
+    get_event_loop_policy = getattr(asyncio, "get_event_loop_policy", None)
+    if get_event_loop_policy is None:
+        return None
+    with warnings.catch_warnings():
+        warnings.simplefilter("ignore", DeprecationWarning)
+        policy = get_event_loop_policy()
+    return getattr(getattr(policy, "_local", None), "_loop", None)

Review Comment:
   You're right, that was fragile. The private-state peek is gone in 
11f51776a6: the helper is now built on `asyncio.Runner`, as you suggested, with 
details in the PR comment below.
   
   ---
   Drafted-by: Claude Code (Fable 5.1); reviewed by @dabla before posting



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to