Opened 15 years ago

Closed 10 years ago

#13843 closed Cleanup/optimization (fixed)

'destroy_geom' filling up the apache error logs.

Reported by: Rozza Owned by: nobody
Component: GIS Version: 1.3
Severity: Normal Keywords:
Cc: ognajd@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Hi when using geodjango my apache error logs get filled up with:

Exception AttributeError: "'NoneType' object has no attribute 'destroy_geom'" in 

Unfortunately, the traceback doesn't give any more information than that. It might be a threading issue similar to #13488.

Attachments (2)

13843.patch (1.2 KB ) - added by Rozza 15 years ago.
Patch to catch exceptions on deletion of already deleted geoms
GEOSContextHandle.patch (606 bytes ) - added by gorodechnyj 13 years ago.
Ignores AttributeError: "'NoneType' object has no attribute 'finishGEOS_r'"

Download all attachments as: .zip

Change History (14)

by Rozza, 15 years ago

Attachment: 13843.patch added

Patch to catch exceptions on deletion of already deleted geoms

comment:1 by Rozza, 15 years ago

Has patch: set

Again I have no idea how to test!

comment:2 by Rozza, 14 years ago

Resolution: wontfix
Status: newclosed

Updated after conversation on the geo_django google group.

The root cause for these problems is the same: the module holding the 
destructor is garbage collected in the dying thread before the geometry 
or I/O object is itself garbage collected (and tries to call the now 
non-existent function). 

To compound the issue, it appears that GC order changes depending on the 
version of Python used, as well as the platform it is running on.  In 
other words, Python 2.7 on Snow Leopard won't show these errors while 
Python 2.5 on Arch Linux will. 

However, for the ticket you opened (#13843), the developer may prevent 
these errors by _not_ creating module-level globals of GEOS geometry 
objects.  Here's an example of a module-level global: 


from django.contrib.gis.geos import GEOSGeometry 
geom = GEOSGeometry('POINT(5 23)') 
def my_view(): 
    do_something_with(geom) 


Instead of having `geom` defined in the global scope, it would be better 
to have it instantiated in the local scope of the view function instead. 

As it stands I'm -1 on the #13843 patch.  While it reduces log noise 
in your case, it masks that there could be an underlying problem with 
the developer's code.  Regardless, I'm keeping the ticket open because 
absent a technological fix, there should be at least note in the 
documentation on how to avoid it. 

-Justin 

comment:3 by kamikaze.is.waiting.you@…, 13 years ago

Easy pickings: unset
Has patch: unset
Needs tests: set
Resolution: wontfix
Severity: Normal
Status: closedreopened
Type: Uncategorized
UI/UX: unset
Version: 1.21.3

Having same problem when editing polygon (from geodjango tutorial of World) in admin part.

in reply to:  3 ; comment:4 by anonymous, 13 years ago

Replying to kamikaze.is.waiting.you@…:

Having same problem when editing polygon (from geodjango tutorial of World) in admin part.

And this doesn't happen every time...

in reply to:  4 comment:5 by anonymous, 13 years ago

Replying to anonymous:

Replying to kamikaze.is.waiting.you@…:

Having same problem when editing polygon (from geodjango tutorial of World) in admin part.

And this doesn't happen every time...

[Fri Oct 14 01:39:24 2011] [notice] caught SIGTERM, shutting down
[Fri Oct 14 01:39:24 2011] [error] Exception AttributeError: "'NoneType' object has no attribute 'finishGEOS_r'" in <bound method GEOSContextHandle.__del__ of <django.contrib.gis.geos.prototypes.threadsafe.GEOSContextHandle object at 0x181b4d0>> ignored
[Fri Oct 14 01:39:24 2011] [error] Exception AttributeError: "'NoneType' object has no attribute 'finishGEOS_r'" in <bound method GEOSContextHandle.__del__ of <django.contrib.gis.geos.prototypes.threadsafe.GEOSContextHandle object at 0x1fc5210>> ignored
[Fri Oct 14 01:39:24 2011] [error] Exception AttributeError: "'NoneType' object has no attribute 'destroy_geom'" in Exception AttributeError: "'NoneType' object has no attribute 'destroy_geom'" in 
[Fri Oct 14 01:39:24 2011] [error] Exception AttributeError: "'NoneType' object has no attribute 'destroy_geom'" in Exception AttributeError: "'NoneType' object has no attribute 'destroy_geom'" in
Last edited 13 years ago by Aymeric Augustin (previous) (diff)

comment:6 by anonymous, 13 years ago

ok. this happens when running on apache/mod_wsgi and doesn't happen when launched as standalone django server (development mode in Eclipse)

Environment:


Request Method: POST
Request URL: http://localhost.com/admin/world/worldborder/239/

Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['localeurl',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.gis',
 'login',
 'mainpage',
 'classifiers',
 'currency_rates',
 'exchange_points',
 'world',
 'south']
Installed Middleware:
('django.middleware.cache.UpdateCacheMiddleware',
 'localeurl.middleware.LocaleURLMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.transaction.TransactionMiddleware',
 'django.middleware.cache.FetchFromCacheMiddleware')


Traceback:
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  307.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  79.         response = view_func(request, *args, **kwargs)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  197.             return view(request, *args, **kwargs)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  28.             return bound_func(*args, **kwargs)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/usr/local/src/virtualenvs/rates.bixority.com/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  24.                 return func(self, *args2, **kwargs2)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/db/transaction.py" in inner
  217.                 res = func(*args, **kwargs)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/contrib/admin/options.py" in change_view
  982.                 self.save_model(request, new_object, form, change=True)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/contrib/admin/options.py" in save_model
  665.         obj.save()
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/db/models/base.py" in save
  460.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  526.                         rows = manager.using(using).filter(pk=pk_val)._update(values)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/db/models/query.py" in _update
  491.         return query.get_compiler(self.db).execute_sql(None)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  869.         cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  735.         cursor.execute(sql, params)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/db/backends/util.py" in execute
  34.             return self.cursor.execute(sql, params)
File "/usr/local/src/virtualenvs/localhost.com/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py" in execute
  44.             return self.cursor.execute(query, args)

Exception Type: DatabaseError at /admin/world/worldborder/239/
Exception Value: invalid byte sequence for encoding "UTF8": 0x00

comment:7 by Aymeric Augustin, 13 years ago

Has patch: set
Needs tests: unset
Patch needs improvement: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

I've encountered this problem myself. Log noise is annoying.

The discussion quoted in comment 3 describes how to resolve it:

the developer may prevent these errors by _not_ creating module-level globals of GEOS geometry object

That's what we should do (if possible).

The problem described in comment 6 is unrelated.

comment:8 by gorodechnyj, 13 years ago

I kept getting my apache error.log flooded with this useless errors:

[Mon Jan 30 15:16:27 2012] [error] Exception AttributeError: "'NoneType' object has no attribute 'finishGEOS_r'" in <bound method GEOSContextHandle.__del__ of <django.contrib.gis.geos.prototypes.threadsafe.GEOSContextHandle object at 0x7faea717e910>> ignored

Although I'm pretty sure that I never use module-level GEOS variables.

by gorodechnyj, 13 years ago

Attachment: GEOSContextHandle.patch added

Ignores AttributeError: "'NoneType' object has no attribute 'finishGEOS_r'"

comment:9 by Aymeric Augustin, 12 years ago

Status: reopenednew

comment:10 by Daniel Sokolowski, 11 years ago

Cc: ognajd@… added

comment:11 by tobych, 11 years ago

Here's the monkey patch we're currently using to work around this (Django 1.4.3):

# https://gist.github.com/tobych/6372218
# Monkey patch to work around https://code.djangoproject.com/ticket/13843
 
import django
from functools import wraps
 
def discard_exceptions(f):
  @wraps(f)
  def wrapper(*args, **kwds):
    try:
      f(*args, **kwds)
    except (AttributeError, TypeError):
      pass
  return wrapper
 
django.contrib.gis.geos.prototypes.threadsafe.GEOSContextHandle.__del__ = \
  discard_exceptions(django.contrib.gis.geos.prototypes.threadsafe.GEOSContextHandle.__del__)
django.contrib.gis.geos.prototypes.io.IOBase.__del__ = \
  discard_exceptions(django.contrib.gis.geos.prototypes.io.IOBase.__del__)
Last edited 11 years ago by tobych (previous) (diff)

comment:12 by Claude Paroz <claude@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 8f334e55be99ae271d82f9b961a2dc6258487d9c:

Fixed #13843 -- Prevented AttributeError during geometry objects deletion

Note: See TracTickets for help on using tickets.
Back to Top