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


##########
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:
   Accessing not one, but two _private vars seems very fragile. Yes, getattr 
"protects" against it, but is this the best way of doing it?



-- 
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