-
-
Notifications
You must be signed in to change notification settings - Fork 420
Giant refactor to move all state into a Kernel struct #1145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1145 +/- ##
===========================================
+ Coverage 9.90% 66.56% +56.65%
===========================================
Files 15 16 +1
Lines 848 963 +115
===========================================
+ Hits 84 641 +557
+ Misses 764 322 -442 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Figured out the deadlock, we can now start writing full tests with |
64ec133
to
b19c5aa
Compare
using ZMQ, JSON, SoftGlobalScope | ||
import Base.invokelatest | ||
import Base: invokelatest, RefValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably using
rather than import
since we only use these, not extend them? Also invokelatest
is exported automatically these days.
(This code dates back to the days before using Foo: bar
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but I think I'd prefer to do those sorts of changes in a later PR. This one is already quite large 😅
src/IJulia.jl
Outdated
setfield!(value, name, x) | ||
end | ||
|
||
function Base.close(kernel::Kernel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be called by a finalizer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that wouldn't be easy because it wait
's on the stdio tasks so it might yield. I think it's ok to rely on the do-constructor closing it in the tests.
Progress update:
To-do:
|
212ff17
to
3c393ba
Compare
I believe this is ready to be reviewed now. One thorny issue is segfaults on windows that appear to be coming from ZMQ, using For reviewers, I've tried to keep the commits atomic so I would recommend reviewing each commit one-by-one. |
Explicitly waiting for the heartbeat thread also seemed to fix it, which seems preferable to |
68e3717
to
0b6e7be
Compare
Back in the green with 0b6e7be 😅 I think this is in pretty good shape now. |
e1c5262
to
9bb03a1
Compare
I went ahead and added a simple precompilation workload in 9bb03a1. On my system it reduces the running time of getting the kernel info and executing Not sure why the tests are failing, it seems to be related to CondaPkg 🤔 Will investigate later, but I believe this is ready for review anyway. |
9bb03a1
to
47a2230
Compare
Back in the green, had to explicitly specify |
Testing locally and installing a kernel, the kernel seems to die as soon as I attempt to connect |
Is the path to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured out the problem I was having, it was crashing at startup for me because comm_open
, comm_close
, and comm_msg
had the wrong signature relative to the invokelatest
call in the event loop.
Github isn't letting me give a suggestion for the comm_close
and comm_msg
functions, but they need to all have the same signature.
f1cd8bf
to
bb7cef4
Compare
Ouch, that's quite a serious oversight 😬 I've added tests and hopefully fixed the comms code in bb7cef4, with the one change of making the Line 114 in 4390ef4
One other thing I noticed is that Lines 85 to 90 in 4390ef4
@stevengj, should we be removing it like the |
@shashi, can you common on the |
bb7cef4
to
9b43adf
Compare
Rebased to fix merge conflicts. About |
(bump) |
bff8a21
to
6c15aa0
Compare
(rebased to fix merge conflicts from #1149) |
6c15aa0
to
a5d0435
Compare
(bump) |
This is the only change in 5.4, in previous versions it was sent on the shell socket.
The Jupyter messaging docs state that all messages on the shell (request) channel shall be ended with a `status: idle` message, and that: "This idle status message indicates that IOPub messages associated with a given request have all been received." Previously we did not attempt to ensure this, which meant that in some cases the `execute_result` message would be published after the `execute_reply` message had been sent. It's still not exactly guaranteed by the `yield()`, but it's something and it makes the `jupyter_kernel_test` tests pass.
This is required by the spec: https://jupyter-client.readthedocs.io/en/latest/messaging.html#introspection
Other notable changes: - Moved `create_profile()` into init.jl so we can use it in `init()` and the precompilation workload. - Added an option to not capture stdin, because during precompilation it's not possible to redirect stdin.
a5d0435
to
72e3590
Compare
Is it known why Windows is failing to precompile here? It seems to build and run fine on my machine. |
Nope, I still need to debug that (bit swamped this week). But glad it works on your machine now 🎉 Do you see a TTFX improvement from the precompilation? |
Yes, I am seeing a slight noticeable reduction in TTFX! |
I should mention though that my main usecase (https://github.com/emacs-jupyter/jupyter) remains super slow the first time and seems to be unaffected by this. But baby steps, and I don't think that should hold back this effort. |
Pretty much what the title says 😛
This is not ready yet but I'm opening it for transparency.There are two reasons for the refactor:Overview:
Almost all global state has been moved into the new
Kernel
struct, and all relevant internal methods now require a kernel be passed to them. That's the bulk of the diff. I've tried to minimize other changes as much as possible, so there should 🤞 be no change in behaviour frommaster
.There are certain fields like
ans
andn
which are documented as globals and must stay global, sosetproperty!(::Kernel,...)
is implemented such that it will copy changes to those fields to their corresponding global variable. Similarly there are certain public methods likeIJulia.history()
that must still work without a kernel argument, so a new_default_kernel
global is defined for normal usage and that's used by default for all public methods.An edge-case are the dictsIn
andOut
which are by default assigned to the corresponding fields of_default_kernel
and will not contain changes from temporary test kernels. I don't think that's a particularly important discrepancy so I'm inclined to ignore it.I implemented a basic test in
waitloop.jl
that spawns the IJulia waitloop and then makes a request to it usingjupyter_client
. This isn't working very well right now because blocking calls to the client causes hangs, I suspect there's a deadlock somewhere.This will need a lot more work before it can be merged, but feel free to review the design already (cc @stevengj, @fredrikekre).
@MasonProtter, you should be able to do... something... with this for a precompilation workload. I would suggest creating a
Kernel
, connecting to some of the sockets with ZMQ.jl, and then sending some mock requests following the wire protocol: https://jupyter-client.readthedocs.io/en/latest/messaging.html#the-wire-protocol