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


##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -511,16 +569,49 @@ def start(
             del constructor_kwargs
             del logger
 
-            try:
-                # Run the child entrypoint
-                _fork_main(child_requests, child_stdout, child_stderr, 
child_logs.fileno(), target)
-            except BaseException as e:
-                import traceback
-
-                with suppress(BaseException):
-                    # We can't use log here, as if we except out of _fork_main 
something _weird_ went on.
-                    print("Exception in _fork_main, exiting with code 124", 
file=sys.stderr)
-                    traceback.print_exception(type(e), e, e.__traceback__, 
file=sys.stderr)
+            if _USE_FORK_EXEC and target is _subprocess_main:
+                # macOS: immediately exec a fresh Python interpreter to 
replace the
+                # inherited ObjC/CoreFoundation state that is not fork-safe.  
Only
+                # for task execution (_subprocess_main); DAG processor and 
triggerer
+                # use different targets and keep bare fork.  The socketpair FDs
+                # survive across exec because we mark them inheritable.
+                try:
+                    import json
+
+                    fds = {
+                        "requests": child_requests.fileno(),
+                        "stdout": child_stdout.fileno(),
+                        "stderr": child_stderr.fileno(),
+                        "logs": child_logs.fileno(),
+                    }
+                    for fd in fds.values():
+                        os.set_inheritable(fd, True)
+
+                    os.environ[_CHILD_FDS_ENV_VAR] = json.dumps(fds)
+                    os.execv(sys.executable, [
+                        sys.executable,
+                        "-c",
+                        "from airflow.sdk.execution_time.supervisor import 
_child_exec_main;"
+                        " _child_exec_main()",
+                    ])
+                    # execv replaces the process -- we never reach here
+                except BaseException as e:
+                    import traceback
+
+                    with suppress(BaseException):
+                        print(f"execv failed, exiting with code 124: {e}", 
file=sys.stderr)
+                        traceback.print_exception(type(e), e, e.__traceback__, 
file=sys.stderr)
+            else:

Review Comment:
   Oh hmmm. Not quite sure. I was just looking for "a little less duplication" 
and "less intended code"



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