JuliaPy / JuliaPy/PythonCall.jl

Freeze the resolved interpreter for child processes

Aberta
#796 0 comentários 0 reações 0 responsáveis Ver no GitHub
enhancement
Linguagem predominante
Julia
Estrelas
1.1k
Forks
86
Merge médio
1d 22h
PRs com merge (30d)
3

Descrição

When PythonCall resolves its interpreter via CondaPkg, each **child process** that loads
PythonCall re-resolves the *same* CondaPkg environment from scratch. Spawn several at once —
e.g. `Distributed` workers for parallel data loading (MLUtils `DataLoader(...; num_workers=N)`
over a PythonCall-backed dataset) — and they serialize on CondaPkg's lock, spamming
`CondaPkg: Waiting for lock to be freed` and redoing work the parent already did.

PythonCall already has the fix, but gates it behind `CI=true` and flags it as a hack
(`src/C/context.jl`, v0.9.35):

```julia
# HACK: If we are using CondaPkg, prevent child processes from using it by explicitly
# setting the executable. ...
# A better solution may be to use some environment variable to "freeze" CondaPkg in
# child processes.
# Only done when CI=true since it's a hack.
if (get(ENV, "CI", "false") == "true") && (CTX.which === :CondaPkg)
ENV["JULIA_PYTHONCALL_EXE"] = CTX.exe_path::String
end
```

Since `JULIA_PYTHONCALL_EXE` is exactly the "freeze" env var the comment asks for (child
processes inherit `ENV`, and `getpref_exe` reads it), the same line solves the general case.

## Proposal

Set `JULIA_PYTHONCALL_EXE` whenever `CTX.which === :CondaPkg`, not only under `CI` — ideally
behind a preference (e.g. `freeze_child_processes`, default `true`) so it can be disabled.
`get!` already leaves a user-set value untouched.

## Workaround

A downstream package can do this itself after init:

```julia
if PythonCall.C.CTX.which === :CondaPkg
get!(ENV, "JULIA_PYTHONCALL_EXE", PythonCall.python_executable_path()::String)
end
```

I've done this in https://github.com/JuliaGenAI/HuggingFaceDatasets.jl/pull/64

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

Start in src/C/context.jl and trace how getpref_exe and CTX.which handle CondaPkg during child-process startup. Verify the existing CI-gated behavior and preference conventions, then confirm that spawned processes inherit the resolved executable without re-resolving CondaPkg and that a user-set JULIA_PYTHONCALL_EXE remains unchanged.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
backend
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Pouca atividade
Clareza
Razoavelmente clara
Facilidade para iniciantes
68/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.