awaitTermination(timeout: Optional[int] = None) → Optional[bool]¶
Waits for the termination of this query, either by
query.stop()or by an exception. If the query has terminated with an exception, then the exception will be thrown. If timeout is set, it returns whether the query has terminated or not within the timeout seconds.
If the query has terminated, then all subsequent calls to this method will either return immediately (if the query was terminated by
stop()), or throw the exception immediately (if the query has terminated with exception).
StreamingQueryException, if this query has terminated with an exception
New in version 2.0.0.
Changed in version 3.5.0: Supports Spark Connect.
- timeoutint, optional
None. The waiting time for specified streaming query to terminate.
- bool, optional
The result whether specified streaming query has terminated or not within the timeout seconds if timeout is set. The
StreamingQueryExceptionwill be thrown if the query has terminated with an exception.
>>> sdf = spark.readStream.format("rate").load() >>> sq = sdf.writeStream.format('memory').queryName('query_awaitTermination').start()
Return whether the query has terminated or not within 5 seconds
>>> sq.awaitTermination(5) False