JuliaPy / JuliaPy/PyCall.jl

Using `@pydef` in a module with `--compile-modules=no`

Ouverte
#570 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Julia
Étoiles
1.5k
Forks
186
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

I appear to be getting the following error when loading loading my package on 0.7 if I'm running julia 0.7 with `--compile-modules=no`:

```
julia> using Keras
ERROR: LoadError: LoadError: ArgumentError: ref of NULL PyObject
Stacktrace:
[1] getindex(::PyCall.PyObject, ::String) at /Users/rory/.playground/share/keras/depot/packages/PyCall/rUul9/src/PyCall.jl:284
[2] pybuiltin at /Users/rory/.playground/share/keras/depot/packages/PyCall/rUul9/src/PyCall.jl:701 [inlined]
[3] #def_py_class#24(::Array{Any,1}, ::Array{Any,1}, ::Function, ::String, ::Array{Tuple{Symbol,Function},1}) at /Users/rory/.playground/share/keras/depot/packages/PyCall/rUul9/src/pyclass.jl:28
[4] (::getfield(PyCall, Symbol("#kw##def_py_class")))(::NamedTuple{(:base_classes, :getsets),Tuple{Array{Any,1},Array{Any,1}}}, ::typeof(PyCall.def_py_class), ::String, ::Array{Tuple{Symbol,Function},1}) at ./none:0
[5] top-level scope at /Users/rory/.playground/share/keras/depot/packages/PyCall/rUul9/src/pyclass.jl:174
[6] include at ./boot.jl:317 [inlined]
[7] include_relative(::Module, ::String) at ./loading.jl:1038
[8] include at ./sysimg.jl:29 [inlined]
[9] include(::String) at /Users/rory/repos/Keras.jl/src/Keras.jl:1
[10] top-level scope at none:0
[11] include at ./boot.jl:317 [inlined]
[12] include_relative(::Module, ::String) at ./loading.jl:1038
[13] _require(::Base.PkgId) at ./loading.jl:950
[14] require(::Base.PkgId) at ./loading.jl:852
[15] macro expansion at ./logging.jl:311 [inlined]
[16] require(::Module, ::Symbol) at ./loading.jl:834
in expression starting at /Users/rory/repos/Keras.jl/src/utils.jl:1
in expression starting at /Users/rory/repos/Keras.jl/src/Keras.jl:78
```

The issue appears to be with:

```
@pydef mutable struct metric
function __init__(self, f::Function, name=nothing)
self[:f] = f
self[:__name__] = name == nothing ? typeof(f).name.mt.name : name
end

function __call__(self, x::PyObject, y::PyObject)
self[:f](Tensor(x), Tensor(y)).o
end
end
```

General observations:
- After getting the above error `pybuiltin("object")` stops working, and produces the same `ArgumentError: ref of NULL PyObject` error.
- Running `using PyCall` before `using Keras` works.
- Running julia normally (e.g., without `--compile-module=no`) also works.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Reproduisez l’échec sur Julia 0.7 avec --compile-modules=no, en comparant `using Keras` au chargement préalable de PyCall. Commencez dans `src/pyclass.jl`, autour de `def_py_class` et de l’exemple `@pydef`, puis vérifiez que `using Keras` ne déclenche plus `ref of NULL PyObject`, tandis que le chargement normal continue de fonctionner.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
julia, python
Domaine
backend
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.