| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
|
||
| audio_stream.stop_stream() | ||
| audio_stream.close() | ||
|
|
There was a problem hiding this comment.
Was this move necessary? I'd prefer to have the function that opened the stream be responsible for closing it.
Sorry, something went wrong.
There was a problem hiding this comment.
I agree with you. But, the thread hangs and doesn't come out of the while loop. So, I had to move here and close when I get out.
Sorry, something went wrong.
There was a problem hiding this comment.
Ah - this is because buff.put(None) is never executed if the above loop is exited because stoprequest.is_set() is True. (this means the blocking buff.get() in _audio_data_generator blocks forever, since it's never given the None to exit from its loop).
If you change the above loop to:
try:
...
except IOError:
pass
finally:
buff.put(None)then you should be able to put this back.
Sorry, something went wrong.
There was a problem hiding this comment.
No, this happens because the stream is stopped and the thread hangs when this thread is still in the loop.
Sorry, something went wrong.
| audio_stream.stop_stream() | ||
| audio_stream.close() | ||
| fill_buffer_thread.join() | ||
| audio_interface.terminate() |
There was a problem hiding this comment.
Any particular reason to remove this line? It seems like good hygiene..
Sorry, something went wrong.
There was a problem hiding this comment.
That might have been a mistake. I will restore it.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
| """ | ||
| while True: | ||
| # Use a blocking get() to ensure there's at least one chunk of data | ||
| while not stoprequest.isSet(): |
There was a problem hiding this comment.
prefer .is_set, for python style conventions. Ditto below.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
|
|
||
|
|
||
| def _audio_data_generator(buff): | ||
| def _audio_data_generator(buff, stoprequest): |
There was a problem hiding this comment.
_audio_data_generator shouldn't need this. Once _fill_buffer gets the signal, it'll add None to the buffer, which will cause this generator to exit.
Sorry, something went wrong.
There was a problem hiding this comment.
But, fill_buffer doesn't add the None unless it receives IOError which it doesn't. Ok let me make one change to _fill_buffer.
Sorry, something went wrong.
There was a problem hiding this comment.
Actually to think of it making both threads stop from the same signal is better.
Sorry, something went wrong.
There was a problem hiding this comment.
Can you explain your reasoning?
Sorry, something went wrong.
There was a problem hiding this comment.
The reasoning: Both reader and writer threads consider the stopsignal. If reader looks at the indirect signal from the writer, we don't know if it needed to stop because there is really a stop signal or an error in the writer's output.
Sorry, something went wrong.
There was a problem hiding this comment.
Hm... sure, okay, I can see that. I think there's a case for just letting _fill_buffer propagate the way it is, but I won't block on it.
Sorry, something went wrong.
There was a problem hiding this comment.
I actually had thought about both cases, but can now also see the case for other option. And now as I am thinking more I think the other option makes more sense :) Let me go back to it.
Sorry, something went wrong.
|
Yes I was able to reproduce this. It did hang on my mac. |
Sorry, something went wrong.
| while True: | ||
| # Use a blocking get() to ensure there's at least one chunk of data | ||
| while not stoprequest.is_set(): | ||
| # Use a blocking get() to ensure there's at least one chunk of data |
There was a problem hiding this comment.
Please remove trailing whitespace
Sorry, something went wrong.
|
|
||
|
|
||
| def _audio_data_generator(buff): | ||
| def _audio_data_generator(buff, stoprequest): |
There was a problem hiding this comment.
Hm... sure, okay, I can see that. I think there's a case for just letting _fill_buffer propagate the way it is, but I won't block on it.
Sorry, something went wrong.
|
|
||
| audio_stream.stop_stream() | ||
| audio_stream.close() | ||
|
|
There was a problem hiding this comment.
Ah - this is because buff.put(None) is never executed if the above loop is exited because stoprequest.is_set() is True. (this means the blocking buff.get() in _audio_data_generator blocks forever, since it's never given the None to exit from its loop).
If you change the above loop to:
try:
...
except IOError:
pass
finally:
buff.put(None)then you should be able to put this back.
Sorry, something went wrong.
| """ | ||
| while True: | ||
| # Use a blocking get() to ensure there's at least one chunk of data | ||
| # Use a blocking get() to ensure there's at least one chunk of data |
There was a problem hiding this comment.
Trailing whitespace
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
|
|
||
| yield _audio_data_generator(buff) | ||
|
|
||
| audio_stream.stop_stream() |
There was a problem hiding this comment.
Any particular reason not to stop the stream before closing? While I'm not certain it's necessary, all the examples stop the stream before closing it.
Sorry, something went wrong.
There was a problem hiding this comment.
Once the stream is stopped, one may not call write or read. And thread _fill_buffer gets stuck.
Sorry, something went wrong.
| except IOError: | ||
| # This happens when the stream is closed. Signal that we're done. | ||
| buff.put(None) | ||
| pass |
There was a problem hiding this comment.
Without this, you'll have a race condition. ie if _audio_data_generator's buff.get() is waiting for data in the buffer when stoprequest is triggered, it could potentially wait forever and never yield a value.
Sorry, something went wrong.
There was a problem hiding this comment.
Nice - thanks for catching that race condition 😁
Looks good - just some polishing of the comments left.
Sorry, something went wrong.
| # This happens when the stream is closed. Signal that we're done. | ||
| pass | ||
| finally: | ||
| buff.put(None) |
There was a problem hiding this comment.
A comment here describing what putting None means would be helpful.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
| # First, a thread that collects audio data as it comes in | ||
| with record_audio(RATE, CHUNK) as buffered_audio_data: | ||
|
|
||
| # stop request |
There was a problem hiding this comment.
Can you make this comment describe what stoprequest is for? Simply repeating the name of the variable isn't helpful.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
| @@ -208,7 +212,11 @@ def main(): | |||
| make_channel('speech.googleapis.com', 443)) as service: | |||
| # For streaming audio from the microphone, there are three threads. | |||
| # First, a thread that collects audio data as it comes in | |||
There was a problem hiding this comment.
This comment should be right above the with block, since that's what it's describing.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
| except queue.Empty: | ||
| break | ||
|
|
||
| # If the data contains None then set stop = True. |
There was a problem hiding this comment.
Comments should describe the meaning and purpose of the code, not just narrate what the code is doing. Maybe something like:
# If `_fill_buffer` adds `None` to the buffer, the audio stream is closed. # Yield the final bit of the buffer and exit the loop.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
| # If the data contains None then set stop = True. | ||
| if None in data: | ||
| stop = True | ||
| data.remove(None) |
There was a problem hiding this comment.
Ah - nice catch.
Sorry, something went wrong.
|
|
||
| def main(): | ||
| # For streaming audio from the microphone, there are three threads. | ||
| # First, a thread that collects audio data as it comes in |
There was a problem hiding this comment.
Sorry - I meant that this comment should be on the below with statement, where it was before. ie since the comment is describing the thread that collects audio data, it should be just before the record_audio call.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
| with record_audio(RATE, CHUNK) as buffered_audio_data: | ||
|
|
||
| # stoprequest is event object which is set in `listen_print_loop`. | ||
| # To indicate that the trancsription should be stopped. |
There was a problem hiding this comment.
trancsription -> transcription
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
| with record_audio(RATE, CHUNK) as buffered_audio_data: | ||
|
|
||
| # stoprequest is event object which is set in `listen_print_loop`. | ||
| # To indicate that the trancsription should be stopped. |
There was a problem hiding this comment.
Line 219 and 220 are the same sentence (otherwise, line 220 is a sentence fragment). Please change to:
# stoprequest is an event object which is set in `listen_print_loop` to indicate that the transcription should be stopped.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
|
|
||
| # stoprequest is event object which is set in `listen_print_loop`. | ||
| # To indicate that the trancsription should be stopped. | ||
| # `_fill_buffer` checks and stops collecting data from audio_stream. |
There was a problem hiding this comment.
I had a bunch of trouble parsing this sentence. Perhaps:
# The `_fill_buffer` thread checks this object, and closes the `audio_stream` once it's set.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks!
Sorry, something went wrong.
|
Okay! I'll merge when all statuses are green. |
Sorry, something went wrong.
|
Does dpebot know he can also merge when someone approves the PR + green status? |
Sorry, something went wrong.
|
I'm not sure what you're asking. Are you suggesting that we should merge PRs before the automated tests pass? |
Sorry, something went wrong.
|
I am asking can dpebot take over when a) someone has approved the PR b) green status. Both a and b are true. |
Sorry, something went wrong.
|
I don't understand what you're saying. Are you stating that - currently - someone has approved this PR AND the PR's status is green? Or are you asking whether dpebot can submit the PR if a OR b are true? Or are you asking whether dpebot can submit the PR when a AND b are true? |
Sorry, something went wrong.
|
If it helps - IIUC, dpebot just waits for travis to turn green before submitting. Currently travis is still waiting for test results, so dpebot is not merging the PR yet. |
Sorry, something went wrong.
|
I thought my question was simple :) In other words I am asking. Do we have to ask dpebot explicitly "merge when everything is green"? Can dpebot not figure that out automatically and do the needful? |
Sorry, something went wrong.
|
I think your question is simple, but you're not expressing the full question, or you're not giving enough context for the question, so it's hard to figure out what you're asking. Perhaps it'd be helpful to structure your questions into three steps:
For example:
It was ambiguous in your original question what you thought the current situation was, and what you expected the situation to be. For instance - what did you mean by 'also'? That implies that there's another situation wherein dpebot will merge, besides when it's approved + green; but you don't describe this other situation you allude to, so there's no way for me to know what you're contrasting. Does that make sense? To answer your question - dpebot listens for travis to complete, and only merges if it has status:success AND the automerge label on it. Telling dpebot to 'merge when green' simply adds the automerge label. We don't want dpebot to just merge all green PRs because eg the user might still be working on the PR (for example, addressing comments from the reviewer), even if the tests pass. |
Sorry, something went wrong.
|
Wow! Travis is sloooow! |
Sorry, something went wrong.
|
Yeah - it's usually one slow-running project in our org that backs everything else up :-/ We might consider changing to circleci, like some of the other teams are doing.. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
@jerjou @jonparrott PTAL