New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Custom Timeout - Closes #8 #14
Conversation
- Now one can set a timeout either through the scons command or directly in SConstruct. Use either of: - Run `scons timeout=TIMEINSECONDS` - This assumes the default SConstruct is used - In SConstruct invoke `setup(env, directories, timeout)` - Add the test - Modify example to simulate a long running task with time.sleep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this! I just have a few suggestions in comments I've left inline for a slightly different way to do this.
nbflow/scons.py
Outdated
env['PRINT_CMD_LINE_FUNC'] = print_cmd_line | ||
env.Decider('timestamp-newer') | ||
if timeout is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it would be nice if we could come up with a way to do this without using global variables (see here for an explanation of why avoiding globals is a good idea).
One way this might be possible is to create a class, say called Builder
, that has an attribute called timeout
and that has a method called build_notebook
. Then here you can create an instance of builder, set the timeout value on it, and then use the method on the instance below in env.Command
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the next commit, intead of using classes, I chose a more functional approach and use only pure functions and define a default value for timeout
in build_notebook
. This seems more cleaner to me.
Because of the nature of env.Command
I pass a new function build_notebook_timeout
which is a partial evaluation of build_notebook
in case a timeout
is set or the build_notebook
function in case no timeout
is passed.
nbflow/example/SConstruct
Outdated
@@ -2,4 +2,8 @@ import os | |||
from nbflow.scons import setup | |||
|
|||
env = Environment(ENV=os.environ) | |||
setup(env, ["analyses"]) | |||
timeout = ARGUMENTS.get('timeout', 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this is something that would be handled by the nbflow code, rather than something users have to put in the SConstruct file. Maybe pass the ARGUMENTS
variable to the setup
function directly and let setup
parse the timeout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next commit fixes this parsing the ARGUMENTS
inside setup
- Replace global with pure functions - Modify setup to parse the ARGUMENTS from SConstruct - Modify conftest to suit the last change
The changes requested were added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
scons timeout=TIMEINSECONDS
- This assumes the default SConstruct is usedsetup(env, directories, timeout)