=
"spawn"
message_queue
=
mp
.
get_context
(
start_method
)
.
Queue
()
server
=
timer
.
LocalTimerServer
(
message
,
max_interval
=
0.01
)
server
.
start
()
spec
=
WorkerSpec
(
fn
=
trainer_func
,
args
=
(
message_queue
,),
...<
OTHER_PARAMS
...>
)
agent
=
agent
.
LocalElasticAgent
(
spec
,
start_method
)
agent
.
run
()
def
trainer_func
(
message_queue
):
timer
.
configure
(
timer
.
LocalTimerClient
(
message_queue
))
with
timer
.
expires
(
after
=
60
):
In the example above if trainer_func takes more than 60 seconds to
complete, then the worker process is killed and the agent retries the worker group.
file_path (str) – str, the path of a FIFO special file to be created.
max_interval (float) – float, max interval in seconds for each watchdog loop.
daemon (bool) – bool, running the watchdog thread in daemon mode or not.
A daemon thread will not block a process to stop.
log_event (Callable[[str, FileTimerRequest | None], None] | None) – Callable[[Dict[str, str]], None], an optional callback for
logging the events in JSON format.
:
file_path (str) – str, the path of a FIFO special file. FileTimerServer
must have created it by calling os.mkfifo().
signal – signal, the signal to use to kill the process. Using a
negative or zero signal will not kill the process.
-
abstract get_expired_timers(deadline)
Returns all expired timers for each worker_id. An expired timer
is a timer for which the expiration_time is less than or equal to
the provided deadline.
- Return type:
dict[str, list[TimerRequest]]
-
abstract register_timers(timer_requests)
Processes the incoming timer requests and registers them with the server.
The timer request can either be an acquire-timer or release-timer request.
Timer requests with a negative expiration_time should be interpreted
as a release-timer request.
scope_id
)
Releases the timer for the scope_id on the worker this
client represents. After this method is
called, the countdown timer on the scope is no longer in effect.