Repository navigation
Allow using PyCall with in-process symbols - #293
Conversation
| islink(path) && (path = readlink(path)) | ||
| path | ||
| else | ||
| error("Unsupported operating system") |
There was a problem hiding this comment.
does /proc/self/exe work on freebsd etc?
|
Ok, I have got pycall basically working with this. There are two remaining (and related questions). They are probably more pyjulia questions, but let's discuss them here, since they affect how this PR will evolve. The first most immediate problem is that deps.jl should be separate for pyjulia from the one for julia itself. Right now, one overrides the other which is annoying. Relatedly, I imagine people might want to use pyjulia from different python installations (e.g. python2/python3). In that case, we'd probably want to use the regular |
|
Maybe in |
|
As for pyjulia's |
|
That sounds good to me. Should there be an environment variable that determines which subdirectory to use? |
|
Well, the problem is that it has to create |
|
I hate using environment variables for something like this. Can't |
|
Yes, it can. I was about to say you'd pay a cost at startup time, but that's only once during precompilation, so I think it's fine. |
Why is this? |
|
Because it has to do it for PyCall and all packages that depend on it and there's no way to tell julia to only do it for those packages. |
|
I'd be a bit surprised if someone needed something that depends on PyCall from inside pyjulia. |
|
PyPlot? |
|
Why would you go through Julia for that if you're embedding Julia inside Python? |
|
You wouldn't, but you might be using a package which has a dependency on it (quite a few packages do). |
|
Should we try to do this in a way that the precompile system can recognize which configuration PyCall is in and just recompile the dependency ji's in place if the config changes? |
|
I'm open to any suggestions. |
|
I suppose since we're intercepting the precompile calls anyway, we could check if PyCall was loaded and if so change the output path. Devious but I somewhat like it. @vtjnash ? |
|
I'd say something like a dummy include_dependency that switched between two choices depending whether we're in in-process or shared library mode. Probably set a module level constant too so it can be checked. |
|
@vtjnash is saying the general solution is overly complicated, but intercepting the precompile call and hardlinking should work fine. |
|
After ruminating on this some more, this is how I think I want this to work: PyCall checks if Python symbols are present in the process and if so does not load any deps.jl, but figures out where the python library is, by looking at where the symbol came from (or alternatively using the python APIs to query this). Then pyjulia does the following:
In the second case we also use the interception trick to figure out if PyCall was loaded and if not put the cache file in the original place (rather than the pyjulia private place) and simply symlink, thereby sharing cache files for packages that do not depend on PyCall. |
|
That sounds workable. |
|
Ok, I've implemented that approach here and in pyjulia. Seems to work decently well. Needs a bit more testing and cleanup. |
|
@stevengj Are you ok with this generally? If so I'll rebase and clean a bit, after which this should be good to go. |
|
LGTM. |
|
rebased. |
|
be sure to bump at least minor when tagging this, there's a chance it may have unintended consequences for dependent packages (hopefully not but won't know until after it gets tagged) |
|
Yup, it's a new feature anyway so it should get a minor bump. |
This is the companion pull request to JuliaPy/pyjulia#54 in order to allow PyCall to use the python symbols already present in the current process. This behavior is currently guarded by the
PYCALL_CURRENT_PROCESSenvironment variable. It may be worth enabling the codepath even when that variable is not set, but my thinking was that since a good amount of special handling is required to make this work properly, it should only be enabled if explicitly requested.