forked from platypush/platypush
Added utility get_entities_engine() function.
This commit is contained in:
parent
60da930e4b
commit
8ccf3e804d
1 changed files with 19 additions and 0 deletions
|
@ -1,4 +1,6 @@
|
||||||
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from threading import Event
|
||||||
from typing import Collection, Optional
|
from typing import Collection, Optional
|
||||||
|
|
||||||
from ._base import (
|
from ._base import (
|
||||||
|
@ -36,6 +38,23 @@ def init_entities_engine() -> EntitiesEngine:
|
||||||
return _engine
|
return _engine
|
||||||
|
|
||||||
|
|
||||||
|
def get_entities_engine(timeout: Optional[float] = None) -> EntitiesEngine:
|
||||||
|
"""
|
||||||
|
Return the running entities engine.
|
||||||
|
|
||||||
|
:param timeout: Timeout in seconds (default: None).
|
||||||
|
"""
|
||||||
|
time_start = datetime.utcnow()
|
||||||
|
while not timeout or (datetime.utcnow() - time_start < timedelta(seconds=timeout)):
|
||||||
|
if _engine:
|
||||||
|
break
|
||||||
|
|
||||||
|
Event().wait(1)
|
||||||
|
|
||||||
|
assert _engine, 'The entities engine has not been initialized'
|
||||||
|
return _engine
|
||||||
|
|
||||||
|
|
||||||
def publish_entities(
|
def publish_entities(
|
||||||
entities: Collection[Entity], callback: Optional[EntitySavedCallback] = None
|
entities: Collection[Entity], callback: Optional[EntitySavedCallback] = None
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
Loading…
Reference in a new issue