Code

Opened 4 years ago

Last modified 8 months ago

#13843 new Cleanup/optimization

'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 4 years ago.
Patch to catch exceptions on deletion of already deleted geoms
GEOSContextHandle.patch (606 bytes) - added by gorodechnyj 2 years ago.
Ignores AttributeError: "'NoneType' object has no attribute 'finishGEOS_r'"

Download all attachments as: .zip

Change History (13)

Changed 4 years ago by Rozza

Patch to catch exceptions on deletion of already deleted geoms

comment:1 Changed 4 years ago by Rozza

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Again I have no idea how to test!

comment:2 Changed 4 years ago by Rozza

  • Resolution set to wontfix
  • Status changed from new to closed

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 follow-up: Changed 3 years ago by kamikaze.is.waiting.you@…

  • Easy pickings unset
  • Has patch unset
  • Needs tests set
  • Resolution wontfix deleted
  • Severity set to Normal
  • Status changed from closed to reopened
  • Type set to Uncategorized
  • UI/UX unset
  • Version changed from 1.2 to 1.3

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

comment:4 in reply to: ↑ 3 ; follow-up: Changed 3 years ago by 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...

comment:5 in reply to: ↑ 4 Changed 3 years ago by anonymous

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 3 years ago by aaugustin (previous) (diff)

comment:6 Changed 3 years ago by anonymous

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 Changed 3 years ago by aaugustin

  • Has patch set
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/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 Changed 2 years ago by gorodechnyj

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.

Changed 2 years ago by gorodechnyj

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

comment:9 Changed 13 months ago by aaugustin

  • Status changed from reopened to new

comment:10 Changed 9 months ago by danols

  • Cc ognajd@… added

comment:11 Changed 8 months ago by tobych

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 8 months ago by tobych (previous) (diff)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.