JuliaPy / JuliaPy/PyCall.jl

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

Aperta
#570 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Julia
Stelle
1.5k
Fork
186
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.