Open ODemidenko opened 6 years ago
With small/new notebooks - all extensions work well. With a big notebook - they don't start.
Unfortunately, although this (timeout) can be caused by nbextensions which take a long time to load, it's also an issue with notebook itself. You can check https://github.com/jupyter/notebook/issues/2075 for details, but essentially as I understand it, what's happening is that
probably I used setTimeout option wrong? Am I right that it should be added to notebook metadata, like this:
To mitigate this issue, you can increase the timeout for requirejs as specified in https://github.com/ipython-contrib/jupyter_contrib_nbextensions/issues/822#issuecomment-269912319. But, this doesn't go in notebook metadata, or notebook config. Instead, you need to add something like the following in your custom.js
:
// default is 30s, increase to 1 minute
window.requirejs.config({waitseconds: 60});
You can find details of where to find/create a custom.js
file at http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/JavaScript%20Notebook%20Extensions.html#custom.js. This (using custom.js
instead of an nbextension) is necessary because it's the only way to guarantee that it gets executed before the notebook load call.
Alternatively, in a strategy that's only just occurred to me (so is untested!) you could delay the (attempted) loading of nbextensions until after the notebook fully loads, using the following in custom.js
:
require(['base/js/namespace', 'base/js/utils', 'base/js/events'], function (Jupyter, utils, events) {
"use strict";
// only bother if we're in notebook view
if (Jupyter.notebook === undefined) return;
// patch load_extensions to delay until after the notebook has fully loaded
var orig_load_extensions = utils.load_extensions;
utils.load_extensions = function () {
var nbexts = arguments;
if (Jupyter.notebook._fully_loaded) return orig_load_extensions.apply(this, nbexts);
return new Promise(function (resolve, reject) {
console.log('deferring loading of nbextensions');
events.one('notebook_loaded.Notebook', function () {
console.log('loading deferred nbextensions');
resolve(orig_load_extensions.apply(this, nbexts));
});
});
};
});
@jcb91 Thank you! It helped! (first approach)
I was having the same problem, with very large notebook, the TOC2 extensions failed to load, in Firefox, jupyter notebook 5.5.0, jupyter_contrib_nbextensions 0.5.0. Increasing the timeout in javascript custom.js worked fine. The notebook needed about 90 seconds to fully load.
Just to mention that there is a typo, the correct attribute is waitSeconds
, not waitseconds
, such that the line to add in custom.js
is
window.requirejs.config({waitSeconds: 120});
Hi all,
I also have a very large NoteBook - more than 1k cells - many of which most are Markdown (~90%) and quite heavy on MathJax. For this NB, I also had trouble getting various extensions to work - loading would timeout as described above. The extensions I was loading were
I'm using stock Jupyter from Debian sid and Google Chrome (unstable).
For me none of the suggestions worked. That is putting
// default is 30s, increase to 1 minute
window.requirejs.config({waitseconds: 60});
(or with even larger values) into ~/.jupyter/custom/custom.js
didn't resolve the issue. The trouble seem to me that in main.min.js
rendering of the NB cells is started immediately after custom/custom
and other extensions have been scheduled for loading. Since there are a great number of cells requestjs
hardly ever have a chance of executing the queued loads, and by the time custom.js
is executed it is too late.
My solution to the problem was inspired by #822 - that is, I add a cell with the content
%%javascript
/** Below because this notebook is pretty large */
var rto = 120;
console.log('NB: Increase require timeout to ' + rto + ' seconds');
window.requirejs.config({waitSeconds: rto});
to the top of the NB. From the log I see that this code is executed early, and in fact, it seems to speed up the loading of the NB in general.
I don't find this to be an issue with the nbextensions - rather it seems a "bug" in notebook/base/js/main.js
. Perhaps it should be reported upstream (if not already done). Perhaps main.js
should have heuristics to modify the requestjs.config(waitSeconds:)
according to the size (in cells) of the NB. Or, perhaps one should be able to set the timeout per NB in the metadata.
It would really be a shame if people went to MatLab or Mathematica because of this.
BTW, it seems that the extension nbTranslate has heuristics to postpone loading until the NB is fully done. Perhaps one can address that issue (i.e., deferred set-up of extensions) in a similar maner for other extensions.
Just my 2€¢
Christian
I'm using stock Jupyter from Debian sid and Google Chrome (unstable).
For me none of the suggestions worked. That is putting
// default is 30s, increase to 1 minute window.requirejs.config({waitseconds: 60});
(or with even larger values) into
~/.jupyter/custom/custom.js
didn't resolve the issue. The trouble seem to me that inmain.min.js
rendering of the NB cells is started immediately aftercustom/custom
and other extensions have been scheduled for loading. Since there are a great number of cellsrequestjs
hardly ever have a chance of executing the queued loads, and by the timecustom.js
is executed it is too late.My solution to the problem was inspired by #822 - that is, I add a cell with the content
%%javascript /** Below because this notebook is pretty large */ var rto = 120; console.log('NB: Increase require timeout to ' + rto + ' seconds'); window.requirejs.config({waitSeconds: rto});
to the top of the NB. From the log I see that this code is executed early, and in fact, it seems to speed up the loading of the NB in general.
In my case, I had this same problem running Firefox in CentOS. I have tested the window.requirejs.config({waitSeconds: 120});
(which worked), but this solution seems to load the notebook faster.
@jcb91
Alternatively, in a strategy that's only just occurred to me (so is untested!) you could delay the https://github.com/ipython-contrib/jupyter_contrib_nbextensions/issues/1195#issuecomment-357756819
Thx, works for me
Hi. With recent install of jupyter core : 4.6.3 jupyter-notebook : 6.0.3
extensions load and fail (as seen in js console) happens before custom.js gets loaded (I judge it from printing to console at the beginning od custom.js) . Hence, no workarounds suggested here worked. Are there any other ways?
Hi all,
I also have a very large NoteBook - more than 1k cells - many of which most are Markdown (~90%) and quite heavy on MathJax. For this NB, I also had trouble getting various extensions to work - loading would timeout as described above. The extensions I was loading were
- nbTranslate
- toc2
- hinterland
- jupyter-js-widgets
I'm using stock Jupyter from Debian sid and Google Chrome (unstable).
For me none of the suggestions worked. That is putting
// default is 30s, increase to 1 minute window.requirejs.config({waitseconds: 60});
(or with even larger values) into
~/.jupyter/custom/custom.js
didn't resolve the issue. The trouble seem to me that inmain.min.js
rendering of the NB cells is started immediately aftercustom/custom
and other extensions have been scheduled for loading. Since there are a great number of cellsrequestjs
hardly ever have a chance of executing the queued loads, and by the timecustom.js
is executed it is too late.My solution to the problem was inspired by #822 - that is, I add a cell with the content
%%javascript /** Below because this notebook is pretty large */ var rto = 120; console.log('NB: Increase require timeout to ' + rto + ' seconds'); window.requirejs.config({waitSeconds: rto});
to the top of the NB. From the log I see that this code is executed early, and in fact, it seems to speed up the loading of the NB in general.
I don't find this to be an issue with the nbextensions - rather it seems a "bug" in
notebook/base/js/main.js
. Perhaps it should be reported upstream (if not already done). Perhapsmain.js
should have heuristics to modify therequestjs.config(waitSeconds:)
according to the size (in cells) of the NB. Or, perhaps one should be able to set the timeout per NB in the metadata.It would really be a shame if people went to MatLab or Mathematica because of this.
BTW, it seems that the extension nbTranslate has heuristics to postpone loading until the NB is fully done. Perhaps one can address that issue (i.e., deferred set-up of extensions) in a similar maner for other extensions.
Just my 2€¢
Christian
Thank you a lot! Had the same problems with Jupyter Notebook v6.1.5, Chromium v87.0.4280.88. Adding that javascript cell, running it and reloading the notebook resolved the issue.
I've found that adding
window.requirejs.config({waitSeconds: 120});
won't help: due to unknown reason in my environment some other code (which code - I did not found) is forcibly setting it back to 30.
This is how I found this: I opened the file
/opt/anaconda3/lib/python3.8/site-packages/notebook/static/components/requirejs/require.js
and added some logging statements:
console.log("checkLoaded", waitInterval, expired, noLoads, reqCalls, stillLoading, needCycleCheck);
and to my surprise waitInterval was equal to 30000 no matter that I've set waitSeconds to 0, then to 180, then to 240 - whatever.
So the BRUTE FORCE patch which I did looks like this: I've set waitInterval to be equal to 0:
function checkLoaded() {
var countOfTrying = 0;
var err, usingPathFallback,
waitInterval = 0,
//It is possible to disable the wait interval by using waitSeconds of 0.
expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
noLoads = [],
reqCalls = [],
stillLoading = false,
needCycleCheck = true;
@ibobak, waitInterval = 0
really helped me, thank you!
With small/new notebooks - all extensions work well. With a big notebook - they don't start. I've tried setTimeout and enabling/disabling Highlighter extension as was suggested in issue 1009 But that helped only once (and I didn't get which advice actually helped). And now the problem continues.
In the JS console I see following error:
probably I used setTimeout option wrong? Am I right that it should be added to notebook metadata, like this:
? BTW: I have just updated nbextensions and this didn't help either