utils

stick_ray.utils

Module Contents

get_or_create_event_loop()[source]

Get a running async event loop if one exists, otherwise create one.

This function serves as a proxy for the deprecating get_event_loop(). It tries to get the running loop first, and if no running loop could be retrieved: - For python version <3.10: it falls back to the get_event_loop

call.

  • For python version >= 3.10: it uses the same python implementation

    of _get_event_loop() at asyncio/events.py.

Ideally, one should use high level APIs like asyncio.run() with python version >= 3.7, if not possible, one should create and manage the event loops explicitly.

Return type:

asyncio.AbstractEventLoop

deterministic_uuid(seed)[source]

Generate a UUID using a deterministic hashing of a seed string.

Parameters:

seed (str) – str, a string seed

Returns:

UUID

Return type:

uuid.UUID

class SerialisableBaseModel[source]

Bases: pydantic.BaseModel

A pydantic BaseModel that can be serialised and deserialised using pickle, working well with Ray.

class Config[source]
validate_assignment = True[source]
arbitrary_types_allowed = True[source]
json_loads[source]
json_dumps[source]
json_encoders[source]
classmethod parse_obj(obj)[source]
Parameters:

obj (Dict[str, Any]) –

Return type:

pydantic.BaseModel

__reduce__()[source]
set_datetime_timezone(dt, offset)[source]

Replaces the datetime object’s timezone with one from an offset.

Parameters:
  • dt (datetime.datetime) – datetime, with out without a timezone set. If set, will be replaced.

  • offset (Union[str, datetime.tzinfo]) – tzinfo, or str offset like ‘-04:00’ (which means EST)

Returns:

datetime with timezone set

Return type:

datetime.datetime

current_utc()[source]

Get the current datetime in UTC, with timezone set to UTC.

Returns:

datetime

Return type:

datetime.datetime

is_key_after_star(func, key)[source]

Checks if a function has a keyword-only argument after a star argument.

Parameters:
  • func (Callable) – Callable to check for keyword-only argument after star argument.

  • key (str) – keyword-only argument to check for.

Returns:

True if key is a keyword-only argument after star argument.