diff --git a/ratapi/matlab.txt b/ratapi/matlab.txt deleted file mode 100644 index 710371e7..00000000 --- a/ratapi/matlab.txt +++ /dev/null @@ -1 +0,0 @@ -C:\Program Files\MATLAB\R2024b\bin\matlab.EXE \ No newline at end of file diff --git a/ratapi/wrappers.py b/ratapi/wrappers.py index 6c3d55db..925a632e 100644 --- a/ratapi/wrappers.py +++ b/ratapi/wrappers.py @@ -1,5 +1,6 @@ """Wrappers for the interface between ratapi and MATLAB custom files.""" +import os import pathlib from contextlib import suppress from typing import Callable @@ -20,10 +21,10 @@ def start_matlab(): """ future = None - with suppress(ImportError): - import matlab.engine - - future = matlab.engine.start_matlab(background=True) + if os.environ.get("DELAY_MATLAB_START", '0') == '0': + with suppress(ImportError): + import matlab.engine + future = matlab.engine.start_matlab(background=True) return future @@ -86,6 +87,22 @@ def handle(*args): return handle +def use_shared_matlab(name, custom_error=""): + """Start MATLAB asynchronously and returns a future to retrieve the engine later. + + Returns + ------- + future : matlab.engine.futureresult.FutureResult + A future used to get the actual matlab engine. + + """ + with suppress(ImportError): + import matlab.engine + + MatlabWrapper.loader = matlab.engine.connect_matlab(name, background=True) + return MatlabWrapper.loader + + class DylibWrapper: """Creates a python callback for a function in dynamic library. @@ -99,7 +116,7 @@ class DylibWrapper: """ def __init__(self, filename, function_name) -> None: - self.engine = ratapi.rat_core.DylibEngine(filename, function_name) + self.engine = RATapi.rat_core.DylibEngine(filename, function_name) def getHandle(self) -> Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], tuple[ArrayLike, float]]: """Return a wrapper for the custom dynamic library function.