[BEAM-759] Implement wait_until_finish method for existing runners.#1762
[BEAM-759] Implement wait_until_finish method for existing runners.#1762aaltay wants to merge 6 commits intoapache:python-sdkfrom
Conversation
|
|
||
| # Actually run the pipeline (all operations above are deferred). | ||
| return p.run() | ||
| return p.run().wait_until_finish() |
There was a problem hiding this comment.
Here, we return the result. However, I don't think the result is actually used. Should we remove "return" for consistency?
There was a problem hiding this comment.
result is used to get aggregated_values. I am keeping the return.
| environment_version=self.environment_version).proto | ||
| # TODO(silviuc): Remove the debug logging eventually. | ||
| logging.info('JOB: %s', job) | ||
| # logging.info('JOB: %s', job) |
There was a problem hiding this comment.
What is the intention here?
There was a problem hiding this comment.
Good catch, reverted. It was my local debugging change.
|
Thank you @charlesccychen. R: @robertwb |
|
Thanks, LGTM. |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): Failed Tests: 3beam_PreCommit_Java_MavenInstall/org.apache.beam:beam-examples-java: 2
beam_PreCommit_Java_MavenInstall/org.apache.beam:beam-runners-apex: 1--none-- |
|
Refer to this link for build results (access rights to CI server needed): |
|
I think that requiring test authors to write wait_until_finished() is quite error prone. Perhaps we could make the test runner "blocking" by default (but parametrizable of course). There is no contract that p.run() return immediately, just that it can return early to provide a nicer API. |
|
@robertwb Thank you, I agree that, it is easy to miss I made the |
|
I was suggesting making the TestRunner blocking by waiting on the
underlying runner.
…On Tue, Jan 10, 2017 at 5:11 PM, Ahmet Altay ***@***.***> wrote:
@robertwb <https://github.com/robertwb> Thank you, I agree that, it is
easy to miss wait_until_finished() in tests.
I made the TestDataflowRunner blocking, but most tests also run with
DirectRunner. Are you suggesting to make DirectRunner blocking by default?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1762 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAdqgdfXY5kOUcn8EZGOUbzTyS8-QqMxks5rRCw5gaJpZM4Lf7vD>
.
|
|
Sorry for the confusion, I see it's a TestPipeline, not TestRunner I think the way to do this would be to override |
|
Since we're on the topic, are we therefore explicitly making the decision that non-testing runners will not block on .run() by default? This makes the more common use case of .run() less intuitive. |
|
Runners are free to block or not as they see fit. Revisiting this for all
SDKs is a bigger question.
…On Fri, Jan 13, 2017 at 12:37 PM, Charles Chen ***@***.***> wrote:
Since we're on the topic, are we therefore explicitly making the decision
that non-testing runners will not block on .run() by default? This makes
the more common use case of .run() less intuitive.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1762 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAdqgU36ikJzmh1Uz4HWh6gUyhbco8Bnks5rR-B8gaJpZM4Lf7vD>
.
|
Also defines the not implemented cancel() method and updates existing usages to use wait_until_finish() instead of blocking runners.
|
@robertwb PTAL. I updated |
|
Refer to this link for build results (access rights to CI server needed): |
robertwb
left a comment
There was a problem hiding this comment.
Mostly looks good. However, I think most of the test should be converted to use TestPipeline rather than manually waiting.
| ('that', ((1, 'that'), )), | ||
| ])) | ||
| p.run() | ||
| p.run().wait_until_finish() |
There was a problem hiding this comment.
Should this be updated to use the TestPipeline instead?
There was a problem hiding this comment.
Updated this and most other tests to use TestPipeline.
| lambda (prefix, candidates): '%s: %s' % (prefix, candidates)) | ||
| | 'write' >> WriteToText(known_args.output)) | ||
| p.run() | ||
| p.run().wait_until_finish() |
There was a problem hiding this comment.
Do we still need this? What happens if we don't have it? (I'd assume these are non-daemon threads we're starting, so the pipeline will still continue to run until complete before the process exits, right?
There was a problem hiding this comment.
We do not need it, removed it.
DirectRunner uses non-daemon threads, and you are right pipeline continue to run until complete before the process exits.
DataflowRunner uses daemon threads. I kept the existing behavior and there is a comment about why it is needed. Pipelines still continue to finish tough because exiting from the runner after job submissions does not cancel the job.
|
|
||
| # Actually run the pipeline (all operations above are deferred). | ||
| p.run() | ||
| p.run().wait_until_finish() |
| # that is very small (VERY) given that we run at least 10 million trials. | ||
| assert_that(result, in_between(3.13, 3.15)) | ||
| p.run() | ||
| p.run().wait_until_finish() |
There was a problem hiding this comment.
same (and the rest of the examples below). Perhaps one example should demonstrate waiting...
| | beam.io.WriteToText(my_options.output)) | ||
|
|
||
| p.run() | ||
| result = p.run() |
There was a problem hiding this comment.
Seems a lot of these snippets could be updated to use TestPipeline, right? (At least as long as it's part of the setup/teardown code, not the actual snippet.) They're never run not under a test...
There was a problem hiding this comment.
Updated most of them. I could not easily update some of these in which the pipeline creation was part of the snippet and it was immediately followed by applying transforms inside the snippet.
There was a problem hiding this comment.
Looks good. I wonder if these should be part of the snippets (including constructing an empty PipelineOptions()) but we should address that as part of the documentation revamp.
There was a problem hiding this comment.
Ack. Maybe. At least some of them could be part of the snippets.
| beam.assert_that(small_but_nontrivial, beam.equal_to(['bb']), | ||
| label='small_but_not_trivial') | ||
| p.run() | ||
| p.run().wait_until_finish() |
There was a problem hiding this comment.
Same for these, we should be using TestPipeline.
| assert_that(pcoll, equal_to(range(1000))) | ||
|
|
||
| pipeline.run() | ||
| pipeline.run().wait_until_finish() |
There was a problem hiding this comment.
Any reason these io tests are not using TestPipeline as well?
|
|
||
| def _is_in_terminal_state(self): | ||
| if not self.has_job: | ||
| return True |
There was a problem hiding this comment.
UNKNOWN is terminal? What if self.job gets assigned later? Or can that not happen?
There was a problem hiding this comment.
I am sorry I missed this in my previous reply.
It cannot happen. apiclient.DataflowApplicationClient.create_job either returns None (in case of error and template jobs) or returns a Job with a job id. It is not assigned later.
| @@ -25,14 +25,16 @@ | |||
| class TestDataflowRunner(DataflowRunner): | |||
There was a problem hiding this comment.
All of this logic feels like it belongs in TestPipeline, not a subclass of DataflowRunner. @markflyhigh
Removed wait_until_finish except for a few exceptions: - tfidf: as an example usage. - some examples in cookbook - they run examples directly and, did not want to update the examples to use TestPipeline. - some snippets - if the pipeline creations is part of the snippet and it was not easy to override.
|
Refer to this link for build results (access rights to CI server needed): |
|
Thank you @robertwb. I updated most of the existing tests to use |
|
Refer to this link for build results (access rights to CI server needed): |
robertwb
left a comment
There was a problem hiding this comment.
Thanks. Just a few minor comments.
| p.run() | ||
| result = p.run() | ||
| # [END pipelines_constructing_running] | ||
| result |
There was a problem hiding this comment.
Is this just to silence lint? Could that be done more explicitly?
There was a problem hiding this comment.
No, leftover code. Removed it. (Did a a global search to find other left over code similar to this but could not.)
| | beam.io.WriteToText(my_options.output)) | ||
|
|
||
| p.run() | ||
| result = p.run() |
There was a problem hiding this comment.
Looks good. I wonder if these should be part of the snippets (including constructing an empty PipelineOptions()) but we should address that as part of the documentation revamp.
|
|
||
| def _is_in_terminal_state(self): | ||
| if not self.has_job: | ||
| return True |
|
|
||
| [testenv:py27] | ||
| deps= | ||
| nose |
There was a problem hiding this comment.
New. Running autocomplete_test outside the testing framework depends on this. (I think the other option is to add it as an install_requires package since tox does setup.py install at first. Adding it as tests_require was not enough.)
|
Thank you @robertwb. PTAL. |
|
Refer to this link for build results (access rights to CI server needed): |
|
Thank you. |
Implement wait_until_finish method for existing runners.
Also defines the not implemented cancel() method and updates existing
usages to use wait_until_finish() instead of blocking runners.
Main changes are in the runners/ folder
runner.py - has the APIs
dataflow_runner.py, direct_runner.py modified to implement the API (moving the existing blocking code around.)
Rest of the changes are mechanical to mainly convert
p.run() to p.run().wait_until_finish() in tests and examples. Changed tests because they run validation after the run and need to block until completion. We may revert the changes in examples. I converted the because in the instructions we directed users to blocking runners before and this change keeps the behavior same.
I have started a local post commit run (not completed yet) and it was successful with the first few tests so far and the changes are same for all tests.
Remaining work after this PR: