Using IPython

Provided your plasm doesn’t use things like ecto_opencv.imshow or other cells that create strange threads that conflict with ipython, you can use IPython, http://ipython.scipy.org, as a front end to ecto scripts. In short, you execute the plasm asynchronously and then spawn an ipython interpreter in the main python interpreter thread:

#!/usr/bin/env python
import ecto, sys
import ecto.ecto_test as ecto_test

plasm = ecto.Plasm()
 
gen = ecto_test.Generate("Gen", step=1.0, start=0.0)
inc = ecto_test.Increment("Increment 0", delay=100)
printer = ecto_test.Printer("Printy")
 
plasm.connect(gen[:] >> inc[:],
              inc[:] >> printer[:])
  
sched = ecto.schedulers.Threadpool(plasm)
sched.execute_async(niter=10)
    
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
ipshell()

You should notice immediately that the console output from the underlying C++ code (the Printer cell) conflicts with the ipython prompt:

% ../doc/source/ipy.py
Threadpool executing in 3 threads.


In [1]: ***** 1 ***** 0x7f96c8004a10
***** 2 ***** 0x7f96c8004a10
***** 3 ***** 0x7f96c8004a10
***** 4 ***** 0x7f96c8004a10
***** 5 ***** 0x7f96c8004a10
***** 6 ***** 0x7f96c8004a10

Ecto provides a function that will redirect the cout and cerr of the ecto cells to a file, reducing the chance that something will interfere with your ipython prompt:

#!/usr/bin/env python
import ecto, sys
import ecto.ecto_test as ecto_test

plasm = ecto.Plasm()

gen = ecto_test.Generate("Gen", step=1.0, start=0.0)
inc = ecto_test.Increment("Increment 0", delay=100)
printer = ecto_test.Printer("Printy")

plasm.connect(gen[:] >> inc[:],
              inc[:] >> printer[:])

sched = ecto.Scheduler(plasm)
ecto.log_to_file("ectolog.txt")
sched.execute_async()

from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
ipshell()

And you will see the output is separated. Try the utility tail to watch the output file: You can then change parameters of running cells in the ipython session while the scheduler is executing.

Also see Command line helpers: getting stats, GUIS, a shell and more automagically ! for enabling this in the command line in your scripts.

ecto.log_to_file((str)arg1) → None :
C++ signature :
void log_to_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
ecto.unlog_to_file() → None :
C++ signature :
void unlog_to_file()