Code for stop exploration after defined time

Is there any way of coding a condition for halting the exploration in course after a set time has passed?
For example, stop the exploration if it has taken more than an hour.
Thank you.

@kaizen, if you launch it interactively, you can always press the stop button (sometime it will tale a bit before it terminates the execution of the multithreaded process).
On the other hand, if you launch it from a batch, AFAIK, there is no way to stop it.

In any case, I think that you need to study carefully that exploration code (filter and timeframe range) to see if there is something that could be improved to reduce its execution time (for example, do not use loops and replace them with arrays processing instead, avoid repetitive calculations, cut the universe of stocks via preliminary screening, etc.).

1 Like

@kaizen There is definitely something wrong with your code if it takes hours to complete. I remember similar case - when the user was complaining that his exploration was running for hours and often led to "out of memory" errors. After small modifications the same code run against 8000+ stocks was completed in 20 seconds :wink: Here is this thread:

You need to identify the reason(s) of your problems. Start from reading this:

Here you can find additional tips how to make your Exploration/Scan/Backtest more efficient. Also follow the links from the first post in the thread below:

I'm sure there is lots of room for improvements in your code. Looking for a way of stopping Exploration after one hour won't take you anywhere...


Ok, thank you all for the info, i'll take a look at these posts.