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


##########
task-sdk/tests/task_sdk/execution_time/test_comms.py:
##########
@@ -216,25 +236,74 @@ def _recv_exactly(sock, n):
             assert results[idx].key == f"key{idx}", f"Out-of-order or missing 
response for thread {idx}"
             assert results[idx].value == f"value{idx}", f"Incorrect value for 
thread {idx}"
 
+    @staticmethod
+    def _answer_in_order(sock, first_read: threading.Event, answer_first: 
threading.Event) -> None:

Review Comment:
   Pulled into module-level `_read_request` / `_respond` (plus `_recv_exactly` 
for exact reads) in 54a00819cf. The two `_serve_one` copies already on main use 
`_serve` now as well.



##########
task-sdk/src/airflow/sdk/execution_time/comms.py:
##########
@@ -245,55 +271,56 @@ class CommsDecoder(Generic[ReceiveMsgType, SendMsgType]):
 
     err_decoder: TypeAdapter[ErrorResponse] = attrs.field(factory=lambda: 
TypeAdapter(ToTask), repr=False)
 
-    _thread_lock: threading.Lock = attrs.field(factory=threading.Lock, 
repr=False)
-    _async_lock: asyncio.Lock = attrs.field(factory=asyncio.Lock, repr=False)
-    _loop_thread_id: int | None = attrs.field(default=None, repr=False, 
init=False)
+    # Reentrant, so that a send() which interrupts its own thread's (a signal 
handler on the main
+    # thread) is let in instead of waiting for itself, and can tell from 
_exchanging whether that
+    # thread was in the middle of a request. The RLock records its owner when 
it is taken, so no
+    # moment is left where the thread holds the lock but is not yet known as 
its holder.
+    _thread_lock: threading.RLock = attrs.field(factory=threading.RLock, 
repr=False)
+    _worker: _RequestWorker = attrs.field(factory=lambda: _RequestWorker(), 
repr=False, init=False)
+    # Whether the thread holding _thread_lock is between writing a request and 
reading its
+    # response. Only that thread can read it as True once it holds the lock 
itself.
+    _exchanging: bool = attrs.field(default=False, repr=False, init=False)

Review Comment:
   Renamed in 54a00819cf.



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