Skip to main content

awaitAnyTermination (StreamingQueryManager)

Waits until any of the queries on the associated SparkSession has terminated since the creation of the context, or since resetTerminated() was called. If any query terminated with an exception, the exception will be thrown. If timeout is set, returns whether any query has terminated within the timeout seconds.

If a query has already terminated, subsequent calls either return immediately (if stopped normally) or throw the exception immediately (if terminated with an exception). Use resetTerminated() to clear past terminations and wait for new ones.

Syntax

awaitAnyTermination(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. Returns None if no timeout is set.

Examples

Python
sdf = spark.readStream.format("rate").load()
sq = sdf.writeStream.format('memory').queryName('this_query').start()
spark.streams.awaitAnyTermination(5)
# True
sq.stop()