Changeset 6ad0e87 in sasmodels


Ignore:
Timestamp:
Mar 20, 2016 11:43:48 AM (9 years ago)
Author:
gonzalezm
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
3a45c2c
Parents:
b9f4c26
Message:

Trying to free the DLL model library in Windows (still not working)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kerneldll.py

    r17bbadd r6ad0e87  
    5151import ctypes as ct 
    5252from ctypes import c_void_p, c_int, c_longdouble, c_double, c_float 
     53import _ctypes 
    5354 
    5455import numpy as np 
     
    125126    if callable(model_info.get('Iq', None)): 
    126127        return PyModel(model_info) 
    127  
     128     
    128129    dtype = np.dtype(dtype) 
    129130    if dtype == generate.F16: 
     
    138139    else: 
    139140        tempfile_prefix = 'sas_' + model_info['name'] + '128_' 
    140  
     141  
    141142    source = generate.convert_type(source, dtype) 
    142143    source_files = generate.model_sources(model_info) + [model_info['filename']] 
     
    188189    Call :meth:`release` when done with the kernel. 
    189190    """ 
     191     
    190192    def __init__(self, dllpath, model_info, dtype=generate.F32): 
    191193        self.info = model_info 
     
    217219        self.Iqxy = self.dll[generate.kernel_name(self.info, True)] 
    218220        self.Iqxy.argtypes = IQXY_ARGS + pd_args_2d + [fp]*Nfixed2d 
     221         
     222        self.release() 
    219223 
    220224    def __getstate__(self): 
     
    230234        kernel = self.Iqxy if q_input.is_2d else self.Iq 
    231235        return DllKernel(kernel, self.info, q_input) 
    232  
     236     
    233237    def release(self): 
    234238        """ 
    235239        Release any resources associated with the model. 
    236240        """ 
    237         pass # TODO: should release the dll 
     241        if os.name == 'nt': 
     242            #dll = ct.cdll.LoadLibrary(self.dllpath) 
     243            dll = ct.CDLL(self.dllpath) 
     244            libHandle = dll._handle 
     245            #libHandle = ct.c_void_p(dll._handle) 
     246            del dll, self.dll 
     247            self.dll = None 
     248            #_ctypes.FreeLibrary(libHandle) 
     249            ct.windll.kernel32.FreeLibrary(libHandle) 
     250        else:     
     251            pass  
    238252 
    239253 
Note: See TracChangeset for help on using the changeset viewer.