Skip to content

input_transaction

messageflux.iodevices.base.input_transaction

InputTransaction

InputTransaction(device)

this is the base class for input transaction objects.

after reading a message from the device (using 'with_transaction=True') the reader should commit/rollback the transaction, to signal the device if the message is done processing or not

calling commit/rollback on a transaction, finishes it. calling commit or rollback multiple times on a transaction is legal but will only execute once. calling rollback after commit or vice versa, will raise an exception

if using the transaction as context (i.e 'with transaction:') it will commit at the end of the context. if an exception was raised during the context, the transaction will be rolled back.

Parameters:

Name Type Description Default
device InputDevice

the input device that returned that transaction

required

device property

device

Returns:

Type Description

the input device that returned that transaction

finished property

finished

Returns:

Type Description

'True' if the transaction was committed/rolled-back, 'False' otherwise

state property

state

the current state of the transaction

commit

commit()

commits the transaction

rollback

rollback()

rolls back the transaction

wait_for_finish

wait_for_finish(timeout=None)

waits for the transaction to finish (commit/rollback). if timeout is not None, after timeout seconds, it will return finished

Parameters:

Name Type Description Default
timeout Optional[float]

the timeout (in seconds) to wait for the transaction to finish

None

Returns:

Type Description
bool

the value of finished

InputTransactionScope

InputTransactionScope(device, with_transaction=True)

Bases: InputTransaction

a helper class for reading several messages inside a transaction scope.

Parameters:

Name Type Description Default
device InputDevice

the input device to read the messages from

required
with_transaction bool

'True' if we should actually use transactions, 'False' otherwise

True

read_message

read_message(cancellation_token, timeout=None)

this method returns a message from the device, and adds its transaction to the transaction scope

Parameters:

Name Type Description Default
cancellation_token Event

the cancellation token for this service. this can be used to know if cancellation was requested

required
timeout Optional[float]

an optional timeout (in seconds) to wait for the device to return a message. after 'timeout' seconds (None means block until message is available). if the device doesn't have a message to return after timeout seconds, it will return None

None

Returns:

Type Description
Optional[ReadResult]

a ReadResult object or None if no message was available. the device headers can contain extra information about the device that returned the message

NULLTransaction

NULLTransaction(device)

Bases: InputTransaction

a transaction object that does nothing. used as placeholder for reading with with_transaction=False

Parameters:

Name Type Description Default
device InputDevice

the input device that returned that transaction

required

TransactionState

Bases: Enum

represents the current state of the transaction

WrongTransactionStateException

WrongTransactionStateException(*args, **kwargs)

Bases: KwargsException

this exception is raised when transaction is in the wrong state for operation