execution#

Module providing additional execution methods.

Functions:

asynchronous(f)

Use for decorating functions that are to execute asynchronously.

timeout_exec(obj, timeout[, args, kwargs])

Executes object with the timeout limit.

timeout_loop(obj, timeout[, args, kwargs, ...])

Loops while specified object does not return expected response.

ansys.fluent.core.utils.execution.asynchronous(f)#

Use for decorating functions that are to execute asynchronously. The decorated function returns a future object. Calling result() on the future object synchronizes the function execution.

Examples

asynchronous execution using @asynchronous decorator

>>> @asynchronous
... def asynchronous_solve(solver_session, number_of_iterations):
...     solver_session.tui.solve.iterate(number_of_iterations)
>>> asynchronous_solve(solver_session_1, 100)

using the asynchronous function directly

>>> asynchronous(solver_session_2.tui.solve.iterate)(100)

synchronous execution of above 2 calls

>>> asynchronous_solve(solver_session_1, 100).result()
>>> asynchronous(solver_session_2.tui.solve.iterate)(100).result()
ansys.fluent.core.utils.execution.timeout_exec(obj, timeout, args=None, kwargs=None)#

Executes object with the timeout limit. Tries to return whatever the provided object returns. If the object returns nothing, this function will return True. If it times out, returns False.

Parameters:
objAny

Object to execute.

timeoutfloat

Time before cancelling execution and returning early.

argsAny, optional

Arguments to be passed to the specified object.

kwargsAny, optional

Keyword arguments to be passed to the specified object.

Examples

Execute time.sleep() for 2 seconds, with a timeout of 1 second:

>>> import time
>>> from ansys.fluent.core.utils.execution import timeout_exec
>>> ret = timeout_exec(time.sleep,timeout=1,args=(2,))
>>> assert ret is False
ansys.fluent.core.utils.execution.timeout_loop(obj, timeout, args=None, kwargs=None, idle_period=0.2, expected='truthy')#

Loops while specified object does not return expected response. Timeouts after specified time has elapsed. Tries to return whatever is returned by the specified object. If nothing is returned before timeout, returns the opposite of the expected value, i.e. True if expected == "falsy" and False if expected == "truthy".

Parameters:
objAny

Object to evaluate while looping if it does not return expected response.

timeoutfloat

Time before cancelling execution and returning early.

argsAny, optional

Arguments to be passed to the specified object.

kwargsAny, optional

Keyword arguments to be passed to the specified object.

idle_periodfloat, optional

Time in seconds to wait between object evaluations, defaults to 0.2 seconds.

expected: str, optional

Possible values are "truthy" or "falsy", indicating what type of return is expected. By default, expects a "truthy" return from the specified object.

Raises:
InvalidArgument

If an unrecognized value is passed for expected.

Examples

Waiting 5 seconds to see if func("test") returns True:

>>> func("test")
False
>>> response = timeout_loop(func, timeout=5.0, args=("test",))

Waiting 5 seconds to see if func2("test",word="hello") returns False:

>>> func2("test", word="hello")
True
>>> response = timeout_loop(func2, timeout=5.0, expected="falsy", args=("test",), kwargs={"word":"hello",})