MiniXC / simple-back

A simple daily python backtester that works out of the box.
Mozilla Public License 2.0
59 stars 12 forks source link

Segmentation fault while running example code in python3.6 #16

Closed fightthepower closed 4 years ago

fightthepower commented 4 years ago

I am getting segmentation fault error while running example code in python3.6

from simple_back.backtester import BacktesterBuilder

builder = (
   BacktesterBuilder()
   .name('JNUG 20-Day Crossover')
   .balance(10_000)
   .calendar('NYSE')
   .compare(['JNUG']) # strategies to compare with
   .live_progress() # show a progress bar using tqdm
   .live_plot() # we assume we are running this in a Jupyter Notebook
)

bt = builder.build()
for day, event, b in bt['2019-1-1':'2020-1-1']:
    pass

This returns

RuntimeError: main thread is not in main loop

>>> Segmentation fault
MiniXC commented 4 years ago

I think I came across this during development at some point, hope I can reproduce it. Are you running it in a notebook? If you are not, disable live_plot which doesn't work in the terminal.

Edit: I get segmentation fault as well when using live_plot in the terminal, will try to improve the current check on if the code is running in a notebook. Unfortunately there is no good way to live-plot in terminal in a non-blocking way, so I suggest you use live_metrics instead.

MiniXC commented 4 years ago

It would be possible to simply switch to blocking plotting in terminal - this slows down the backtester significantly though. Would pair it with a warning about performance.

fightthepower commented 4 years ago

No I am not using a notebook and removing live_plot solved the problem, Thank you

MiniXC commented 4 years ago

3721b5948f1b17a5bdf5232dfb625eaa6ccdb7c1 added live plotting from the shell as long as you use live_plot(blocking=True). It will be slow, but it will work. When setting live_plot without blocking from the shell, a warning will be raised.