Repository navigation
Closed
Description
I noticed that import julia.<julia module> prints a lot of UndefVarError when <julia module> exports undefined variables. I think exporting undefined variables is better be avoided ideally. However, it seems that pyjulia explicitly allows it by suppressing all exceptions
Lines 155 to 162 in 2eb704c
| def isafunction(julia, julia_name, mod_name=""): | |
| code = "isa({}, Function)".format(julia_name) | |
| if mod_name: | |
| code = "isa({}.{}, Function)".format(mod_name, julia_name) | |
| try: | |
| return julia.eval(code) | |
| except: | |
| return False |
Anyway, here is an example:
Python 3.6.4 (default, Jan 5 2018, 02:35:40)
[GCC 7.2.1 20171224] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import julia
>>> j = julia.Julia()
>>> j.using('DiffEqBase')
>>> import julia.DiffEqBase
UndefVarError(:ConstantLagDDEProblem)UndefVarError(:ConstantLagDDEProblem)UndefVarError(:DAEParameterizedFunction)UndefVarError(:DAEParameterizedFunction)UndefVarError(:DDEParameterizedFunction)UndefVarError(:DDEParameterizedFunction)UndefVarError(:DEParameters)UndefVarError(:DEParameters)UndefVarError(:HasParamFuncs)UndefVarError(:HasParamFuncs)UndefVarError(:Mesh)UndefVarError(:Mesh)UndefVarError(:OutputParameterizedFunction)UndefVarError(:OutputParameterizedFunction)UndefVarError(:ParameterizedFunction)UndefVarError(:ParameterizedFunction)UndefVarError(:ProbParameterizedFunction)UndefVarError(:ProbParameterizedFunction)UndefVarError(:SecondOrderSDEProblem)UndefVarError(:SecondOrderSDEProblem)UndefVarError(:construct_correlated_noisefunc)UndefVarError(:construct_correlated_noisefunc)UndefVarError(:has_paramfuncs)UndefVarError(:has_paramfuncs)UndefVarError(:is_sparse_noise)UndefVarError(:is_sparse_noise)UndefVarError(:isautodifferentiable)UndefVarError(:isautodifferentiable)UndefVarError(:noise_class)UndefVarError(:noise_class)UndefVarError(:num_params)UndefVarError(:num_params)UndefVarError(:param_values)UndefVarError(:param_values)UndefVarError(:set_param_values!)UndefVarError(:set_param_values!)UndefVarError(:white_noise_func_wrapper)UndefVarError(:white_noise_func_wrapper)UndefVarError(:white_noise_func_wrapper!)UndefVarError(:white_noise_func_wrapper!)>>>When I initialize it with julia.Julia(debug=True), I get
...
exception occured? None
exception occured? None
exception occured? None
exception occured? 140476532807120
Retrieving exception infos...
libjulia stderr = 140476567600544
UndefVarError(:white_noise_func_wrapper)show called ...
exception occured? 140476532807296
Retrieving exception infos...
libjulia stderr = 140476567600544
UndefVarError(:white_noise_func_wrapper)show called ...
exception occured? 140476532807472
Retrieving exception infos...
libjulia stderr = 140476567600544
UndefVarError(:white_noise_func_wrapper!)show called ...
exception occured? 140476532807648
Retrieving exception infos...
libjulia stderr = 140476567600544
UndefVarError(:white_noise_func_wrapper!)show called ...
It looks like this happens because Base.show is called whenever exception occurred:
Lines 416 to 432 in 2eb704c
| def check_exception(self, src=None): | |
| exoc = self.api.jl_exception_occurred() | |
| self._debug("exception occured? " + str(exoc)) | |
| if not exoc: | |
| # self._debug("No Exception") | |
| self.api.jl_exception_clear() | |
| return | |
| self._debug("Retrieving exception infos...") | |
| stderr = self.api.jl_stderr_obj() | |
| self._debug("libjulia stderr = " + str(stderr)) | |
| self.api.jl_call2(self.api.show, stderr, exoc) | |
| self._debug("show called ...") | |
| # self.api.jl_printf(self.api.jl_stderr_stream(), "\n"); | |
| exception_type = self.api.jl_typeof_str(exoc).decode('utf-8') | |
| raise JuliaError(u'Exception \'{}\' occurred while calling julia code:\n{}' | |
| .format(exception_type, src)) |
But why do you need to print it when JuliaError is going to be raised anyway?
(see also: SciML/diffeqpy#24)
Metadata
Metadata
Assignees
Labels
No labels
Activity
tkf commentedon Apr 28, 2018
Here is a workaround I came up with:
tkf commentedon Apr 28, 2018
Probably
j.api.show = j._call('tuple')should be used instead ofj.api.show = j._call('identity')sincej.api.showis called with two arguments. I have no idea why above snippet works.Do not show exception in non-debugging mode
stevengj commentedon Apr 28, 2018
The correct fix here is just to fix import. The current design, where it attempts to import every symbol in the module all at once, is broken; see also #144.
tkf commentedon Apr 28, 2018
The problem here is more basic than module loader; it's about
Julia.check_exception. Implementing lazy import still requires this to be fixed.