dianfu commented on a change in pull request #16467:
URL: https://github.com/apache/flink/pull/16467#discussion_r687486737
##########
File path:
flink-python/src/main/java/org/apache/flink/streaming/api/operators/python/AbstractPythonFunctionOperator.java
##########
@@ -317,9 +329,41 @@ private void checkInvokeFinishBundleByTime() throws
Exception {
protected void invokeFinishBundle() throws Exception {
if (elementCount > 0) {
- pythonFunctionRunner.flush();
- elementCount = 0;
+ AtomicBoolean flushThreadFinish = new AtomicBoolean(false);
+ AtomicReference<Throwable> exceptionReference = new
AtomicReference<>();
+ flushThreadPool.submit(
+ () -> {
+ try {
+ pythonFunctionRunner.flush();
+ } catch (Throwable e) {
+ exceptionReference.set(e);
+ } finally {
+ flushThreadFinish.set(true);
+ // interrupt the progress of takeResult to avoid
the main thread is
+ // blocked forever.
+ ((BeamPythonFunctionRunner)
pythonFunctionRunner).notifyNoMoreResults();
+ }
+ });
+ Tuple2<byte[], Integer> resultTuple;
+ while (!flushThreadFinish.get()) {
+ resultTuple = pythonFunctionRunner.takeResult();
+ if (resultTuple.f1 != 0) {
+ emitResult(resultTuple);
+ emitResults();
+ }
+ }
emitResults();
+ Throwable flushThreadThrowable = exceptionReference.get();
+ if (flushThreadThrowable != null) {
Review comment:
if (flushThreadThrowable != null) {
throw new Exception(flushThreadThrowable);
}
##########
File path:
flink-python/src/main/java/org/apache/flink/streaming/api/operators/python/AbstractPythonFunctionOperator.java
##########
@@ -158,6 +167,9 @@ public void close() throws Exception {
pythonFunctionRunner.close();
pythonFunctionRunner = null;
}
+ if (flushThreadPool != null) {
+ flushThreadPool.shutdown();
Review comment:
flushThreadPool = null
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]