Skip to content
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

Merged
merged 2 commits into from Apr 22, 2018
Merged

Add Custom Timeout - Closes #8 #14

merged 2 commits into from Apr 22, 2018

Conversation

ELC
Copy link
Contributor

@ELC ELC commented Apr 22, 2018

  • 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 for this feature
  • Modify example to simulate a long running task with time.sleep

- 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
@ELC ELC changed the title ✨ Add Custom Timeout - Closes #8 Add Custom Timeout - Closes #8 Apr 22, 2018
Copy link
Owner

@jhamrick jhamrick left a 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:
Copy link
Owner

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.

Copy link
Contributor Author

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.

@@ -2,4 +2,8 @@ import os
from nbflow.scons import setup

env = Environment(ENV=os.environ)
setup(env, ["analyses"])
timeout = ARGUMENTS.get('timeout', 0)
Copy link
Owner

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?

Copy link
Contributor Author

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
@ELC
Copy link
Contributor Author

ELC commented Apr 22, 2018

The changes requested were added

Copy link
Owner

@jhamrick jhamrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants