blocking_dict

stick_ray.blocking_dict

Module Contents

async parallel(*awaitables, return_exceptions=False)[source]

Run multiple requests in parallel.

Parameters:
  • *awaitables (Awaitable) – awaitables to run in parallel

  • return_exceptions (bool) – if True, return exceptions instead of raising them

Returns:

list of results

Return type:

List[Union[Any, BaseException]]

class BlockingDict[source]

Bases: object

A blocking dictionary that can be used to store and retrieve items in a thread-safe manner.

keys()[source]

Returns a list of keys in the dictionary.

Returns:

list of keys

Return type:

List[Hashable]

size()[source]

Returns the size of the dictionary.

Returns:

size

Return type:

int

async put(key, value)[source]

Put an item into the dictionary with the given key. Overwrites the existing value with same key, if it exists.

Parameters:
  • key (Hashable) – key

  • value (Any) – value

async peek(key, timeout=None)[source]

Get an item from the dictionary, leaving the item there, optionally blocking and with timeout.

Parameters:
  • key (Hashable) – key

  • timeout (Optional[float]) – timeout in seconds to wait when blocking.

Returns:

item matching key

Raises:

asyncio.Timeout if timeout elapsed and item not found

Return type:

Any

has(key)[source]

Check if the dictionary contains the given key.

Parameters:

key (Hashable) – key

Returns:

True if key is in dictionary, False otherwise

Return type:

bool

async delete(key)[source]

Delete the given key from the dictionary.

Parameters:

key (Hashable) – key