Skip to content

Fix OpenLineage DeprecationWarning about fork() on Python 3.12+#70161

Closed
br413 wants to merge 2 commits into
apache:mainfrom
br413:fix/openlineage-fork-py312
Closed

Fix OpenLineage DeprecationWarning about fork() on Python 3.12+#70161
br413 wants to merge 2 commits into
apache:mainfrom
br413:fix/openlineage-fork-py312

Conversation

@br413

@br413 br413 commented Jul 21, 2026

Copy link
Copy Markdown

Summary

  • Remove \os.fork()-based task event emission in the OpenLineage listener
  • Extract operator metadata in the parent process; emit lifecycle events via picklable _emit_task_instance_event()\ and \ProcessPoolExecutor\ with \ orkserver\ context
  • Use \ orkserver\ multiprocessing context for scheduler-side DAG-run and manual state-change emissions

Problem

On Python 3.12+, the OpenLineage listener emits:

\
DeprecationWarning: This process is multi-threaded, use of fork() may lead to deadlocks in the child.
\\

This came from _fork_execute()\ calling \os.fork()\ during task lifecycle events, and from \ProcessPoolExecutor\ defaulting to the \ ork\ start method on Linux.

Approach

Task lifecycle handlers (\on_running, \on_success, \on_failure, \on_skipped) follow the same two-phase pattern as DAG-run listeners:

  1. Parent process: metadata extraction while ORM/task objects are available
  2. Pool worker (forkserver): adapter emission + metrics via \submit_callable(_emit_task_instance_event, ...)\

This preserves process isolation for OL transport code without \os.fork()\ in multi-threaded worker/scheduler processes.

Test plan

  • \pytest providers/openlineage/tests/unit/openlineage/plugins/test_listener.py\
  • CI provider tests for \openlineage\ pass
  • \prek run --all-files\

Closes #47160

@eladkal

eladkal commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This change looks odd to me.
Did you test it?

br413 added 2 commits July 22, 2026 01:30
Remove os.fork-based task event emission and use forkserver for
ProcessPoolExecutor to avoid DeprecationWarning in multi-threaded processes.

Closes apache#47160
Extract metadata in the parent listener process and emit events via picklable _emit_task_instance_event() with forkserver-backed pool workers, preserving process isolation without os.fork() in multi-threaded processes.
@br413
br413 force-pushed the fix/openlineage-fork-py312 branch from 5f79428 to 978ed8b Compare July 22, 2026 07:33
@br413

br413 commented Jul 22, 2026

Copy link
Copy Markdown
Author

Thanks for the review, @eladkal — fair question.

The first version removed \os.fork()\ by calling lifecycle handlers inline, which dropped the process isolation the fork path provided. I've updated the approach to match what we already do for DAG-run listeners and manual state-change emissions:

  1. Metadata extraction stays in the parent process (where ORM / task objects are available).
  2. Adapter emission runs via \submit_callable\ → \ProcessPoolExecutor\ with \forkserver\ context, using a new picklable module-level _emit_task_instance_event()\ (same pattern as _emit_manual_state_change_event\ / _run_adapter_method).

This removes the Python 3.12 \DeprecationWarning\ without running OL transport code synchronously in the multi-threaded worker/scheduler process.

Rebased onto latest \main\ and pushed. Happy to address any further feedback.

@mobuchowski

Copy link
Copy Markdown
Contributor

#68708 - should fix this issue rather than using forkserver

@eladkal

eladkal commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

#68708 - should fix this issue rather than using forkserver

Great so closing this one as solved by #68708

@eladkal eladkal closed this Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenLineage provider emits warning about use of fork() on Python 3.12

3 participants