VishakBaddur commented on code in PR #77020:
URL: https://github.com/apache/airflow/pull/77020#discussion_r4656334003
##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1805,6 +1820,9 @@ def wait(self) -> int:
self._monitor_subprocess()
finally:
self.selector.close()
+ if self._gc_frozen:
+ gc.unfreeze()
Review Comment:
I think the unconditional `gc.unfreeze()` here can undo the freeze that
LocalExecutor and Celery workers already inherit.
`gc.unfreeze()` releases the whole permanent generation, not just what this
`start()` froze. On main:
- LocalExecutor with the `fork` start method calls `gc.freeze()` before
forking its workers and unfreezes only in the parent
(`_spawn_workers_with_gc_freeze`), so each worker stays frozen. Workers run
tasks through `BaseExecutor.run_workload` -> `supervise_task` in that same
process.
- Celery freezes in `on_celery_import_modules` and unfreezes in
`on_celery_worker_ready`, both in the main process, so the prefork children
forked at startup stay frozen and call `supervise()` from `execute_workload`.
So after the first task, the objects those workers inherited are unfrozen
between tasks, and the next full collection can split the pages #58365 / #62212
kept shared. Quick check of the semantics:
```python
import gc, os
gc.freeze()
if os.fork() == 0:
print(gc.get_freeze_count()) # non-zero, inherited
gc.freeze(); gc.unfreeze()
print(gc.get_freeze_count()) # 0
os._exit(0)
```
Maybe only freeze when nothing is frozen yet, keeping the task-runner
pre-import on its current gate:
```python
bare_fork = target is _subprocess_main and not use_exec
if bare_fork:
_import_task_runner_before_fork()
gc_frozen = bare_fork and gc.get_freeze_count() == 0
```
A test that calls `gc.freeze()` before `start()` and checks
`gc.get_freeze_count()` is still non-zero after `wait()` would cover 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]