Exemple #1
0
 /// <summary>
 /// Dispose Method
 /// </summary>
 /// <remarks>
 /// The Dispose method provides a way to explicitly release the
 /// Python object represented by a PyObject instance. It is a good
 /// idea to call Dispose on PyObjects that wrap resources that are
 /// limited or need strict lifetime control. Otherwise, references
 /// to Python objects will not be released until a managed garbage
 /// collection occurs.
 /// </remarks>
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (Runtime.Py_IsInitialized() > 0 && !Runtime.IsFinalizing)
         {
             IntPtr gs = PythonEngine.AcquireLock();
             Runtime.XDecref(obj);
             obj = IntPtr.Zero;
             PythonEngine.ReleaseLock(gs);
         }
         disposed = true;
     }
 }
Exemple #2
0
        public object Dispatch(ArrayList args)
        {
            IntPtr gs = PythonEngine.AcquireLock();
            object ob = null;

            try
            {
                ob = TrueDispatch(args);
            }
            catch (Exception e)
            {
                PythonEngine.ReleaseLock(gs);
                throw e;
            }

            PythonEngine.ReleaseLock(gs);
            return(ob);
        }
Exemple #3
0
 /// <summary>
 /// Dispose Method
 /// </summary>
 /// <remarks>
 /// The Dispose method provides a way to explicitly release the
 /// Python objects represented by a PythonException.
 /// If object not properly disposed can cause AppDomain unload issue.
 /// See GH#397 and GH#400.
 /// </remarks>
 public void Dispose()
 {
     if (!disposed)
     {
         if (Runtime.Py_IsInitialized() > 0 && !Runtime.IsFinalizing)
         {
             IntPtr gs = PythonEngine.AcquireLock();
             Runtime.XDecref(_pyType);
             Runtime.XDecref(_pyValue);
             // XXX Do we ever get TraceBack? //
             if (_pyTB != IntPtr.Zero)
             {
                 Runtime.XDecref(_pyTB);
             }
             PythonEngine.ReleaseLock(gs);
         }
         GC.SuppressFinalize(this);
         disposed = true;
     }
 }
Exemple #4
0
 internal GILState()
 {
     state = PythonEngine.AcquireLock();
 }