[1.2.X] Fixed #13488 -- No longer generate unhandled exceptions that may occur when destructors of global GEOS I/O objects are called on process termination.
Backport of r15378 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15379 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
776bf6e5f7
commit
432ff76035
|
@ -20,18 +20,6 @@ class GEOSContext(threading.local):
|
||||||
|
|
||||||
thread_context = GEOSContext()
|
thread_context = GEOSContext()
|
||||||
|
|
||||||
def call_geos_threaded(cfunc, args):
|
|
||||||
"""
|
|
||||||
This module-level routine calls the specified GEOS C thread-safe
|
|
||||||
function with the context for this current thread.
|
|
||||||
"""
|
|
||||||
# If a context handle does not exist for this thread, initialize one.
|
|
||||||
if not thread_context.handle:
|
|
||||||
thread_context.handle = GEOSContextHandle()
|
|
||||||
# Call the threaded GEOS routine with pointer of the context handle
|
|
||||||
# as the first argument.
|
|
||||||
return cfunc(thread_context.handle.ptr, *args)
|
|
||||||
|
|
||||||
class GEOSFunc(object):
|
class GEOSFunc(object):
|
||||||
"""
|
"""
|
||||||
Class that serves as a wrapper for GEOS C Functions, and will
|
Class that serves as a wrapper for GEOS C Functions, and will
|
||||||
|
@ -43,6 +31,9 @@ class GEOSFunc(object):
|
||||||
# take an additional context handle parameter.
|
# take an additional context handle parameter.
|
||||||
self.cfunc = getattr(lgeos, func_name + '_r')
|
self.cfunc = getattr(lgeos, func_name + '_r')
|
||||||
self.threaded = True
|
self.threaded = True
|
||||||
|
# Create a reference here to thread_context so it's not
|
||||||
|
# garbage-collected before an attempt to call this object.
|
||||||
|
self.thread_context = thread_context
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# Otherwise, use usual function.
|
# Otherwise, use usual function.
|
||||||
self.cfunc = getattr(lgeos, func_name)
|
self.cfunc = getattr(lgeos, func_name)
|
||||||
|
@ -50,7 +41,12 @@ class GEOSFunc(object):
|
||||||
|
|
||||||
def __call__(self, *args):
|
def __call__(self, *args):
|
||||||
if self.threaded:
|
if self.threaded:
|
||||||
return call_geos_threaded(self.cfunc, args)
|
# If a context handle does not exist for this thread, initialize one.
|
||||||
|
if not self.thread_context.handle:
|
||||||
|
self.thread_context.handle = GEOSContextHandle()
|
||||||
|
# Call the threaded GEOS routine with pointer of the context handle
|
||||||
|
# as the first argument.
|
||||||
|
return self.cfunc(self.thread_context.handle.ptr, *args)
|
||||||
else:
|
else:
|
||||||
return self.cfunc(*args)
|
return self.cfunc(*args)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue