We start by sepecifying that %%isolate
will police inputs and outputs.
In strict
mode, if post
or pre
clause is specified and their content
does not match what the cell actually does, an exception is raised.
In [1]:
%isolatemode strict echo
We can ask isolate-magic to automatically detect the pre/post conditions by omitting the clauses. In this case no exception would ever be raised
In [2]:
%%isolate name(InitializeAuto)
a = 10
b = 10
If a post
clause is give, it must match the cell's side effects on the user namespace
In [3]:
%%isolate name(Initialize) post(a, b)
a = 10
b = 20
Now observe the PostConditionException, if 'a' is not propertly declared
In [4]:
%%isolate name(BadInitialize) post(b)
a = 10
b = 20
Cells without a %%isolate magic are ignored. Even if they modify a variable declared in another cell.
In [5]:
%%isolate
b
Out[5]:
If it wasn't obvious, libraries can be handled in the same way.
In [6]:
%%isolate name(ImportModules) post(os)
import os
import os.path
We see a run a cell that access a variable (b
) that not declared in pre
;
The cell has run in full. But we still see the PreConditionError
In [7]:
%%isolate name(Diagonistics) post(b) pre()
try:
print(b)
except NameError:
print 'A NameError is caught'
finally:
b = 20
If we don't export, the value in the top-level namespace is left as-is
In [8]:
%%isolate name(SetB)
b = 10
In [9]:
%%isolate name(TestUntaintedNameSpace) post()
b = 5
In [10]:
%%isolate name(GetB)
b
Out[10]:
In [11]:
%%isolate name(Iterative) pre(a) post(a)
a = a + 1
This produces a list of the cells, with inputs and outputs. The layout here sucks, but it shows the basis for something that could be improved.
In [12]:
g = %dag
g
Out[12]:
This is the beginnings of a debugging helper that I found useful.
In [13]:
im = %iso_debug
In [14]:
im.STRICT
Out[14]:
In [15]:
%debug
In [15]: