Skip to content

Conversation

@tkf
Copy link
Member

@tkf tkf commented Aug 1, 2018

In the current master, self.sprint and self.showerror are used to handle errors:

pyjulia/julia/core.py

Lines 457 to 476 in e617ad9

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
# If, theoretically, an exception happens in early stage of
# self.__init__, showerror and sprint as below does not work.
# Let's use jl_typeof_str in such case.
try:
sprint = self.sprint
showerror = self.showerror
except AttributeError:
res = None
else:
res = self.api.jl_call2(void_p(self.api.convert),
void_p(self.api.PyObject),
void_p(exoc))

They are set at the end of api.Julia.__init__

pyjulia/julia/core.py

Lines 432 to 433 in e617ad9

self.sprint = self.eval('sprint')
self.showerror = self.eval('showerror')

but self._call(u"using PyCall") has to be called before this to initialize pyjulia in the first place:

self._call(u"using PyCall")

The error case in self._call(u"using PyCall") was actually handled in check_exception with the except AttributeError branch. However, my PR #162 just got pulled broke this horribly since accessing self.sprint invokes LegacyJulia.__getattr__ which then in turn tries to initialize api.Julia. There are several ways to fix it but the first thing we can do is to avoid inheritance and separate out the "magic" object api.LegacyJulia from the core api.Julia.

It fixes the error I mentioned in #175 (but not the issue itself).

@stevengj stevengj merged commit 9dfc132 into JuliaPy:master Aug 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants