Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

76 prevent user from instanciating two reachySDK #98

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/reachy_v2_sdk/reachy_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@
# from .dynamixel_motor import DynamixelMotor


def singleton(cls: Any, *args: Any, **kw: Any) -> Any:
instances = {}

def _singleton(*args: Any, **kw: Any) -> Any:
if cls not in instances:
instances[cls] = cls(*args, **kw)
else:
raise ConnectionError("Cannot open 2 robot connections in the same kernel.")
return instances[cls]

return _singleton


@singleton
class ReachySDK:
"""The ReachySDK class handles the connection with your robot.

Expand Down