I often develop notebooks using VSCode jupyter code cells like the one below and execute them via python script.py
in tmux. The problem is that currently I don't have a function for executed_as_jupyter_code_cell
and some code is executed unnecessarily. Can I check this somehow?
A workaround is to simply set a custom env variable, but maybe there's a direct solution?
#%% load
def load(x):
...
if executed_as_jupyter_code_cell():
y=load(x)
#%% transform
def transform(y):
...
if executed_as_jupyter_code_cell():
z=transform(y)
#%% pipe
from concurrent.futures import ProcessPoolExecutor
def pipe(x):
y=load(x)
z=transform(y)
save(z)
with ProcessPoolExecutor() as exec:
exec.map(pipe, some_long_iterable)