Skip to main content

awaitTermination (StreamingQuery)

Waits for the termination of this query, either by stop() or by an exception. If the query has terminated with an exception, the exception will be thrown. If timeout is set, returns whether the query has terminated within the timeout seconds.

If the query has already terminated, subsequent calls either return immediately (if stopped normally) or throw the exception immediately (if terminated with an exception).

Syntax

awaitTermination(timeout=None)

Parameters

Parameter

Type

Description

timeout

int, optional

The number of seconds to wait. If not set, waits indefinitely.

Returns

bool or None

Returns True or False if timeout is set, indicating whether the query terminated within the timeout. Returns None if no timeout is set.

Examples

Python
sdf = spark.readStream.format("rate").load()
sq = sdf.writeStream.format('memory').queryName('query_awaitTermination').start()
sq.awaitTermination(5)
# False
sq.stop()