Changeset 1146 for framspy/frams.py
- Timestamp:
- 08/03/21 14:00:12 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/frams.py
r1141 r1146 14 14 15 15 For sample usage, see frams-test.py and FramsticksLib.py. 16 17 If you want to run many independent instances of this class in parallel, use the "multiprocessing" module and then each process 18 that uses this module will initialize it and get access to a separate instance of the Framsticks library. 16 19 17 20 For interfaces in other languages (e.g. using the Framsticks library in your C++ code), see ../cpp/frams/frams-objects.h … … 285 288 286 289 original_dir = os.getcwd() 287 os.chdir(lib_path) # because under Windows, frams-objects.dll requires other dll's which reside in the same directory, so we must change current dir for them to be found while loading the main dll 290 os.chdir(lib_path) # because under Windows, frams-objects.dll requires other dll's which reside in the same directory, so we must change current dir for them to be found while loading the main dll. 291 # TODO in python 3.8+ and Windows, use os.add_dll_directory(lib_path) instead of os.chdir()? And maybe for linux we no longer need chdir() and "./", but use absolute path? 288 292 abs_data = os.path.abspath('data') # use absolute path for -d and -D so python is free to cd anywhere without confusing Framsticks 289 293 # for the hypothetical case without lib_path the abs_data must be obtained from somewhere else … … 298 302 global c_api # access global variable 299 303 if lib_path is not None and os.name == 'posix': 300 lib_name = './' + lib_name # currently we always have lib_path (even if it is incorrect) but hypothetically it could work with lib_path==None andload .so from some default system path without './'304 lib_name = './' + lib_name # currently we always have lib_path (even if it is incorrect), but hypothetically it could work with lib_path==None and then load .so from some default system path without './' 301 305 try: 302 c_api = ctypes.CDLL(lib_name) # should be a separate instance and no globals if we want multiple threads to use this module (todo?)306 c_api = ctypes.CDLL(lib_name) # if accessing this module from multiple threads, they will all share a single c_api and access the same copy of the library and its data. If you want separate independent copies, read the comment at the top of this file on using the "multiprocessing" module. 303 307 except OSError as e: 304 308 print("*** Could not find or open '%s' from '%s'.\n*** Did you provide proper arguments and is this file readable?\n" % (lib_name, os.getcwd()))
Note: See TracChangeset
for help on using the changeset viewer.