Skip to content
Open
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
19 changes: 14 additions & 5 deletions thorlabs_apt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,10 +1343,16 @@ def set_dc_settled_current_loop_parameters(self, settled_proportional,
"""DC settled current loop: fast forward"""


def _load_library():
_lib = None

def load_library():
"""
Loads the APT.dll shared library. Calls APTInit.
"""
global _lib
if _lib is not None:
# The library has already been loaded
return
# load library
if (os.name != 'nt'):
raise Exception("Your operating system is not supported. " \
Expand All @@ -1370,17 +1376,20 @@ def _load_library():
"%s" % _get_error_text(err_code))
if (lib.EnableEventDlg(False) != 0):
raise Exception("Couldn't disable event dialog.")
# Store the library globally
_lib = lib
return lib

_lib = None
_lib = _load_library()
load_library()

import atexit
@atexit.register
def _cleanup():
def cleanup():
"""
Calls APTCleanUp
Calls APTCleanUp.
"""
global _lib
if (_lib is not None):
_lib.APTCleanUp()
_lib = None