Re: (Win32 API) callback to Python, threading hiccups
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: (Win32 API) callback to Python, threading hiccups

From: Gregory Bond <gnb@itga.com.au>
Date: Fri Jul 08 2005 - 09:05:18 CEST

Tim Roberts wrote:

>>> PyGILState_STATE gil = PyGILState_Ensure();
>>> result = PyEval_CallObject(my_callback, arglist);
>>> PyGILState_Release(gil);
>>> Py_DECREF(arglist);
>>> Py_DECREF(result);

> If someone else holds a reference to "arglist", then the
> DECREF is just a nice, atomic decrement. If no one else holds a reference
> to "arglist", then it's quite safe to delete it.

What if anothere thread takes the GIL as soon as you release it, and is
attempting to allcate a new opbject, and (at the same time - you might
be on a multiprocessor!) your PyDECREF removes the last reference and
starts freeing objects?
Received on Thu Sep 29 16:49:47 2005