Skip to content

Commit 0adfb29

Browse files
committed
Fix lack of processed nodes counter to handle cyclic dependencies.
1 parent 6a94634 commit 0adfb29

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/jupyter_contrib_nbextensions/nbextensions/execution_dependencies/execution_dependencies.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ define([
2929
return {
3030
load_ipython_extension: function () {
3131
console.log('[execution_dependencies] patching CodeCell.execute');
32-
var orig_execute = codecell.CodeCell.prototype.execute; // keep original cell execute function
32+
var orig_execute = codecell.CodeCell.prototype.execute; // keep original cell execute function
3333
CodeCell.prototype.execute = function (stop_on_error) {
34-
var root_tags = this.metadata.tags || []; // get tags of the cell executed by the user (root cell)
35-
if(root_tags.some(tag => /=>.*/.test(tag))) { // if the root cell contains any dependencies, resolve dependency tree
34+
var root_tags = this.metadata.tags || []; // get tags of the cell executed by the user (root cell)
35+
if(root_tags.some(tag => /=>.*/.test(tag))) { // if the root cell contains any dependencies, resolve dependency tree
3636
var root_cell = this;
3737
var root_cell_id = root_cell.cell_id;
38-
var cells_with_id = Jupyter.notebook.get_cells().filter(function (cell, idx, cells) { // ...get all cells which have at least one id (these are the only ones we could have in deps)
38+
var cells_with_id = Jupyter.notebook.get_cells().filter(function (cell, idx, cells) { // ...get all cells which have at least one id (these are the only ones we could have in deps)
3939
var tags = cell.metadata.tags || [];
4040
return (cell === root_cell || tags.some(tag => /#.*/.test(tag)));
4141
});
4242

4343
console.log('[execution_dependencies] collecting ids and dependencies...');
4444
var cell_map = {}
4545
var dep_graph = {}
46-
cells_with_id.forEach(function (cell) { // ...get all identified cells (the ones that have at least one #tag)
46+
cells_with_id.forEach(function (cell) { // ...get all identified cells (the ones that have at least one #tag)
4747
var tags = cell.metadata.tags || [];
48-
var cell_ids = tags.filter(tag => /#.*/.test(tag)).map(tag => tag.substring(1)); // ...get all identifiers of the current cell and drop the #
48+
var cell_ids = tags.filter(tag => /#.*/.test(tag)).map(tag => tag.substring(1)); // ...get all identifiers of the current cell and drop the #
4949
if(cell === root_cell){
5050
if(cell_ids.length < 1) {
5151
cell_ids.push(root_cell.cell_id); // ...use internal root cell id for internal usage
@@ -55,7 +55,7 @@ define([
5555
}
5656
}
5757

58-
var dep_ids = tags.filter(tag => /=>.*/.test(tag)).map(tag => tag.substring(2)); // ...get all dependencies and drop the =>
58+
var dep_ids = tags.filter(tag => /=>.*/.test(tag)).map(tag => tag.substring(2)); // ...get all dependencies and drop the =>
5959

6060
cell_ids.forEach(function (id) {
6161
//console.log('ID:', id, 'deps: ', dep_ids.toString())
@@ -80,6 +80,7 @@ define([
8080
in_degree[dep] = in_degree[dep] === undefined ? 1 : ++in_degree[dep];
8181
processing_queue.unshift(dep);
8282
}
83+
processed_nodes++;
8384
}
8485

8586
console.log('[execution_dependencies] starting topological sort...');

0 commit comments

Comments
 (0)