Skip to content

Commit

Permalink
Fixed #13488 -- No longer generate unhandled exceptions that may occu…
Browse files Browse the repository at this point in the history
…r when destructors of global GEOS I/O objects are called on process termination.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15378 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jbronn committed Jan 31, 2011
1 parent b8a8066 commit 553adfa
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions django/contrib/gis/geos/prototypes/threadsafe.py
Expand Up @@ -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
Expand All @@ -43,14 +31,22 @@ def __init__(self, func_name):
# 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)
self.threaded = False self.threaded = False


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)


Expand Down

0 comments on commit 553adfa

Please sign in to comment.