Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seemingly random crashes when used with uWSGI, Django and Celery on MacOS #167

Closed
ryankuczka opened this issue Feb 4, 2014 · 33 comments
Closed
Assignees
Labels
crash Problems preventing documents from being rendered

Comments

@ryankuczka
Copy link

I am using WeasyPrint with Django and Celery and seemingly random errors occur. I have a Django model which has a file field that is a pdf and a celery task which generates these pdfs using WeasyPrint.

The first error occurs on our web server and occurs on seemingly random requests and we receive the traceback below:

Traceback (most recent call last):

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 103, in get_response
    resolver_match = resolver.resolve(request.path_info)

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 319, in resolve
    for pattern in self.url_patterns:

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 347, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)

  File "/sites/myApp/urls.py", line 16, in <module>
    admin.autodiscover()

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
    import_module('%s.admin' % app)

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/djcelery/admin.py", line 274, in <module>
    class PeriodicTaskAdmin(admin.ModelAdmin):

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/djcelery/admin.py", line 276, in PeriodicTaskAdmin
    form = periodic_task_form()

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/djcelery/admin.py", line 246, in periodic_task_form
    current_app.loader.import_default_modules()

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/djcelery/loaders.py", line 138, in import_default_modules
    self.autodiscover()

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/djcelery/loaders.py", line 141, in autodiscover
    self.task_modules.update(mod.__name__ for mod in autodiscover() or ())

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/djcelery/loaders.py", line 176, in autodiscover
    for app in settings.INSTALLED_APPS])

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/djcelery/loaders.py", line 195, in find_related_module
    return importlib.import_module('%s.%s' % (app, related_name))

  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)

  File "/sites/myApp/apps/pdfs/tasks.py", line 6, in <module>
    from apps.pdfs.models import PdfModel

  File "/sites/myApp/apps/pdfs/models.py", line 15, in <module>
    from apps.pdfs.utils import pdf_utils

  File "/sites/myApp/apps/pdfs/utils/pdf_utils.py", line 3, in <module>
    from weasyprint import HTML, CSS

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/weasyprint/__init__.py", line 304, in <module>
    from .css import PARSER, preprocess_stylesheet

  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/weasyprint/css/__init__.py", line 29, in <module>
    from . import properties

ImportError: cannot import name properties

This exact error occurs with a relatively high frequency, although nowhere near all requests and it starts at seemingly random times. Restarting the uwsgi process which runs the server "solves" the problem.

This issue is also "solved" when I remove djcelery, since djcelery no longer tries to autoload all my tasks modules and WeasyPrint is no longer imported down the line at this point in time, only when it is required.

I originally thought this error would be related to issue #10 but I am not sure because none of the fixes in that issue seemed to work and I am also able to import and use WeasyPrint generally, it just seems to fail in this one specific case.

We also get an error on the machines which run celery workers. We have a Django management command which runs every 3 minutes, and about once a day, we receive the following traceback:

Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/core/management/base.py", line 222, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/core/management/base.py", line 254, in execute
    self.validate()
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/core/management/base.py", line 280, in validate
    num_errors = get_validation_errors(s, app)
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/db/models/loading.py", line 166, in get_app_errors
    self._populate()
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/db/models/loading.py", line 72, in _populate
    self.load_app(app_name, True)
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/db/models/loading.py", line 96, in load_app
    models = import_module('.models', app_name)
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/sites/myApp/apps/pdfs/models.py", line 15, in <module>
    from apps.pdfs.utils import pdf_utils
  File "/sites/myApp/apps/pdfs/utils/pdf_utils.py", line 3, in <module>
    from weasyprint import HTML, CSS
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/weasyprint/__init__.py", line 304, in <module>
    from .css import PARSER, preprocess_stylesheet
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/weasyprint/css/__init__.py", line 30, in <module>
    from . import computed_values
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/weasyprint/css/computed_values.py", line 18, in <module>
    from .. import text
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/weasyprint/text.py", line 195, in <module>
    gobject = dlopen(ffi, 'gobject-2.0', 'libgobject-2.0-0')
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/weasyprint/text.py", line 192, in dlopen
    return ffi.dlopen(names[0])  # pragma: no cover
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/cffi/api.py", line 112, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/home/ubuntu/.virtualenvs/myApp/local/lib/python2.7/site-packages/cffi/api.py", line 369, in _make_ffi_library
    path = ctypes.util.find_library(name)
  File "/usr/lib/python2.7/ctypes/util.py", line 224, in find_library
    return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
  File "/usr/lib/python2.7/ctypes/util.py", line 213, in _findSoname_ldconfig
    f = os.popen('/sbin/ldconfig -p 2>/dev/null')
OSError: [Errno 12] Cannot allocate memory

I have attempted to check the obvious issue of is the server out of memory which doesn't seem to be the case, and it also seemed odd that the error is the exact same every time. The management command also runs successfully 3 minutes before and 3 minutes after. Also, this occurs across 3 different machines, at the same time.

Both of these errors seem to occur when Django or Celery dynamically import something which eventually imports from WeasyPrint, and both seem to happen randomly as I have been unable to ever reproduce these errors myself.

@SimonSapin
Copy link
Member

Most of #10 does not apply anymore as WeasyPrint moved away from PyGObject and PyGTK. What is relevant from #10 is that you can sometimes get ImportError: cannot import name properties when the problem is in fact with importing something else, but I don’t know an easy way to debug this. The most likely suspects are CFFI and lxml, as they involve C code.

Other than that, I’m sorry but I don’t know how to help. The second error is definitely in the realm of CFFI, though. Try asking on #pypy @ Freenode (which also covers CFFI) or on CFFI’s issue tracker what could cause this.

@NotSqrt
Copy link

NotSqrt commented May 22, 2014

Had the exact same errors today : WeasyPrint is simply imported in one of our Django app, and fails with these tracebacks.

I believe it has something to do with threading : we use Gunicorn, and when simultaneous AJAX calls are processed, only 1 succeeds...

@liZe
Copy link
Member

liZe commented Mar 8, 2016

@NotSqrt @ryankuczka Is this bug fixed using the current versions of the dependencies?

@liZe liZe added the crash Problems preventing documents from being rendered label Mar 8, 2016
@ryankuczka
Copy link
Author

@liZe if I remember correctly, upgrading a while back seemed to resolve the ImportError: cannot import name properties though I don't remember exactly when...

As for the other issue I had, I eventually removed all imports of weasyprint from the module level so that it was only imported when it was actually used which "resolved" the issue for me. I no longer use weasyprint in this project so I can't comment on if the issues still exist today.

@liZe
Copy link
Member

liZe commented Mar 8, 2016

@ryankuczka Thank you.

@NotSqrt
Copy link

NotSqrt commented Mar 9, 2016

@liZe I haven't seen it recently, And was not able to reproduce it right now.

@NotSqrt
Copy link

NotSqrt commented Mar 9, 2016

We moved the import weasyprint inside the function instead of the top of the module ..

@liZe
Copy link
Member

liZe commented Mar 9, 2016

@NotSqrt Thank you too, it's very useful. I bet it has something to do with uWSGI's "magic" forking, as explained in this StackOverflow post. Did you use uWSGI (last question, I promise :p)?

@NotSqrt
Copy link

NotSqrt commented Mar 9, 2016

At that time, it was gunicorn, in its regular config.

@liZe
Copy link
Member

liZe commented Mar 9, 2016

Well, gunicorn doesn't preload the application before forking, as explained in the documentation. Sad :/.

@wiltzius
Copy link

Has anyone learned anything more about this issue?

Lazy imports (i.e. importing weasyprint only in the function that uses it) don't seem to help at this point.

I'm also running into the issue using weasyprint under gunicorn, but gunicorn does now support preloading the application before forking. Loading application code pre or post fork both seem to fail when executing HTML() though (with no exception, I'm guessing its a segfault getting swallowed somewhere).

Any guidance appreciated!

@wiltzius
Copy link

(and I'm happy to provide any debug information that might be helpful)

@liZe
Copy link
Member

liZe commented Apr 10, 2017

@wiltzius If you could find anything like a traceback or a segfault error (may be found in dmesg), that would be really useful.

@liZe
Copy link
Member

liZe commented Apr 10, 2017

(Also: there's a lot of recent activity in https://github.com/fdemmer/django-weasyprint, may be useful to ask them too).

@wiltzius
Copy link

Sure! Here's an example segfault:


Thread 0x000070000d9a8000 (most recent call first):
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 856 in check_reload
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 833 in periodic_reload
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754 in run
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801 in __bootstrap_inner
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 774 in __bootstrap

Current thread 0x00007fffaf0b13c0 (most recent call first):
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/text.py", line 618 in __init__
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/text.py", line 829 in create_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/text.py", line 1139 in line_widths
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/preferred.py", line 246 in inline_line_widths
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/preferred.py", line 182 in inline_min_content_width
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/inlines.py", line 83 in get_next_linebox
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/inlines.py", line 51 in iter_line_boxes
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 481 in block_container_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 97 in block_box_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 69 in block_level_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 604 in block_container_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 97 in block_box_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 69 in block_level_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 604 in block_container_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 97 in block_box_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 69 in block_level_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 604 in block_container_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 97 in block_box_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 69 in block_level_layout
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/pages.py", line 513 in make_page
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/pages.py", line 567 in make_all_pages
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/__init__.py", line 53 in layout_document
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/document.py", line 334 in _render
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/__init__.py", line 143 in render
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/weasyprint/__init__.py", line 180 in write_pdf
  File "/Users/wiltzius/Documents/welkin/dingo/util/pdf_utils.py", line 11 in write_pdf
  File "/Users/wiltzius/Documents/welkin/dingo/util/pdf_utils.py", line 33 in create_pdf_file
  File "/Users/wiltzius/Documents/welkin/dingo/resources/fax.py", line 99 in create
  File "/Users/wiltzius/Documents/welkin/dingo/lib/api/handler.py", line 99 in execute
  File "/Users/wiltzius/Documents/welkin/dingo/lib/api/handler.py", line 178 in create
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 501 in _requestonly_view
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 460 in mapped_view
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 385 in viewresult_to_response
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 245 in _secured_view
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 305 in predicate_wrapper
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 329 in attr_view
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 596 in __call__
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/router.py", line 163 in handle_request
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 63 in tm_tween
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/tweens.py", line 21 in excview_tween
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/router.py", line 217 in invoke_subrequest
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/router.py", line 242 in __call__
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/paste/deploy/config.py", line 291 in __call__
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176 in handle_request
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135 in handle
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 30 in accept
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 68 in run_for_one
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 124 in run
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/workers/base.py", line 131 in init_process
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/arbiter.py", line 578 in spawn_worker
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/arbiter.py", line 611 in spawn_workers
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/arbiter.py", line 544 in manage_workers
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/arbiter.py", line 202 in run
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/app/base.py", line 72 in run
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/app/base.py", line 203 in run
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/gunicorn/app/pasterapp.py", line 210 in paste_server
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/paste/deploy/util.py", line 56 in fix_call
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 189 in server_wrapper
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 339 in serve
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 360 in run
  File "/Users/wiltzius/Documents/ENV/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 58 in main
  File "/Users/wiltzius/Documents/ENV/bin/pserve", line 11 in <module>```

@wiltzius
Copy link

Thanks for the quick response, I appreciate it!

@wiltzius
Copy link

I asked over there too, thanks for the tip.

@liZe
Copy link
Member

liZe commented Apr 10, 2017

I've been using WeasyPrint in multithreaded Flask-based applications for a long time and I never hit this error… There must be something strange with gunicorn (I use uWSGI), but it's hard to find what.

@wiltzius
Copy link

Perhaps significantly it's multi-process usage that's causing problems, not multi-threaded. Previously we ran it under waitress, which is multithreaded but single process. Does that give any clues? Are you using uWSGI with multithreading or multiprocessing (I believe it supports both)?

I could switch us to uWSGI, but unfortunately Celery is going to be harder to ditch...

@wiltzius
Copy link

Also, this is on MacOS. I'm not sure if the issue is present on Linux. From my first quick test it looks like it isn't an issue on Linux, but there are a lot of variables between my dev laptop and a linux server...

@liZe
Copy link
Member

liZe commented Apr 10, 2017

Are you using uWSGI with multithreading or multiprocessing (I believe it supports both)?

It supports both and I use both.

I could switch us to uWSGI, but unfortunately Celery is going to be harder to ditch...

I'd prefer find what's going on 😄.

Also, this is on MacOS.

Ah, OK. Does it work with waitress on MacOS?

@wiltzius
Copy link

Figuring out what's going on sounds great :)

Yes, it works with waitress (using ~20 threads and never had an issue) on MacOS.

@wiltzius
Copy link

Further interesting news: it appears that it actually runs fine in Celery's forked worker processes. So the issue does appear specific to gunicorn!

@liZe liZe self-assigned this Apr 10, 2017
@liZe
Copy link
Member

liZe commented Apr 10, 2017

So the issue does appear specific to gunicorn!

Good to know, thanks a lot for your help! I'll try to find what's happening as soon as I can get some time.

@wiltzius
Copy link

Thanks, I appreciate the help today :)

@wiltzius
Copy link

Confirmed that it works with uwsgi for me too.

@wiltzius
Copy link

It seems I spoke too soon. This is utterly mysterious to me, but somehow between last night and this morning I started getting segfaults under uwsgi too. Here's an example, which has a bit more information than the gunicorn trace I posted above:


Thread 0x000070000d716000 (most recent call first):

Current thread 0x00007fffe4d1f3c0 (most recent call first):
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/text.py", line 618 in __init__
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/css/computed_values.py", line 583 in strut_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/inlines.py", line 85 in get_next_linebox
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/inlines.py", line 51 in iter_line_boxes
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 481 in block_container_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 97 in block_box_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 69 in block_level_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 604 in block_container_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 97 in block_box_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 69 in block_level_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 604 in block_container_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 97 in block_box_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 69 in block_level_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 604 in block_container_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 97 in block_box_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/blocks.py", line 69 in block_level_layout
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/pages.py", line 513 in make_page
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/pages.py", line 567 in make_all_pages
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/layout/__init__.py", line 53 in layout_document
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/document.py", line 334 in _render
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/__init__.py", line 143 in render
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/weasyprint/__init__.py", line 180 in write_pdf
  File "/Users/tom/Documents/welkin/dingo/util/pdf_utils.py", line 11 in write_pdf
  File "/Users/tom/Documents/welkin/dingo/resources/user_consent_form.py", line 53 in create
  File "/Users/tom/Documents/welkin/dingo/lib/api/handler.py", line 99 in execute
  File "/Users/tom/Documents/welkin/dingo/lib/api/handler.py", line 178 in create
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 501 in _requestonly_view
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 460 in mapped_view
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 385 in viewresult_to_response
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 245 in _secured_view
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 305 in predicate_wrapper
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 329 in attr_view
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/config/views.py", line 596 in __call__
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/router.py", line 163 in handle_request
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 63 in tm_tween
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/tweens.py", line 21 in excview_tween
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/router.py", line 217 in invoke_subrequest
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/pyramid/router.py", line 242 in __call__
  File "/Users/tom/Documents/ENV/lib/python2.7/site-packages/paste/deploy/config.py", line 291 in __call__
!!! uWSGI process 42005 got Segmentation Fault !!!
*** backtrace of 42005 ***
0   uwsgi                               0x000000010a438bdc uwsgi_backtrace + 44
1   uwsgi                               0x000000010a439113 uwsgi_segfault + 51
2   libsystem_platform.dylib            0x00007fffdc01cb3a _sigtramp + 26
3   ???                                 0x0000000114d00050 0x0 + 4644143184
4   libsystem_c.dylib                   0x00007fffdbe52497 raise + 26
5   libsystem_platform.dylib            0x00007fffdc01cb3a _sigtramp + 26
6   ???                                 0x0000000000000000 0x0 + 0
7   CoreFoundation                      0x00007fffc66691ab ____initDayChangedNotification_block_invoke + 187
8   libdispatch.dylib                   0x00007fffdbdd78fc _dispatch_client_callout + 8
9   libdispatch.dylib                   0x00007fffdbdd78b9 dispatch_once_f + 38
10  CoreFoundation                      0x00007fffc6667aa9 __CFNotificationCenterGetLocalCenter_block_invoke + 201
11  libdispatch.dylib                   0x00007fffdbdd78fc _dispatch_client_callout + 8
12  libdispatch.dylib                   0x00007fffdbdd78b9 dispatch_once_f + 38
13  CoreFoundation                      0x00007fffc66679c9 CFNotificationCenterGetLocalCenter + 41
14  CoreText                            0x00007fffc7c5862c _Z24_CTFontCollectionCreatedPK18__CTFontCollection + 59
15  CoreText                            0x00007fffc7c6865f CTFontCollectionCreateFromAvailableFonts + 210
16  libpangocairo-1.0.dylib             0x00000001187213e0 pango_core_text_font_map_init + 138
17  libgobject-2.0.dylib                0x00000001185919a4 g_type_create_instance + 621
18  libgobject-2.0.dylib                0x000000011858164c g_object_new_internal + 56
19  libgobject-2.0.dylib                0x00000001185810e9 g_object_newv + 493
20  libgobject-2.0.dylib                0x0000000118580ec5 g_object_new + 193
21  libpangocairo-1.0.dylib             0x000000011871e1c9 pango_cairo_font_map_get_default + 41
22  libpangocairo-1.0.dylib             0x000000011871cadc pango_cairo_create_context + 20
23  libpangocairo-1.0.dylib             0x000000011871cb29 pango_cairo_create_layout + 17
24  libffi.dylib                        0x00007fffdae64f1c ffi_call_unix64 + 76
25  ???                                 0x0000000118d330e0 0x0 + 4711461088
*** end of backtrace ***
DAMN ! worker 1 (pid: 42005) died, killed by signal 11 :( trying respawn ...
Respawned uWSGI worker 1 (new pid: 42031)
Python auto-reloader enabled```

@wiltzius
Copy link

(this is on weasyprint 0.36, MacOS, and the following brew package versions:

libffi 3.0.13
cairo 1.14.8
gdk-pixbuf 2.36.2
pango 1.40.3
libxml2 2.9.4 )

@liZe liZe changed the title Seemingly random errors when used with Django and Celery Seemingly random crashes when used with Django and Celery on MacOS Jul 1, 2017
@liZe liZe changed the title Seemingly random crashes when used with Django and Celery on MacOS Seemingly random crashes when used with uWSGI, Django and Celery on MacOSu Jul 1, 2017
@liZe liZe changed the title Seemingly random crashes when used with uWSGI, Django and Celery on MacOSu Seemingly random crashes when used with uWSGI, Django and Celery on MacOS Jul 1, 2017
@dlaxar
Copy link

dlaxar commented Jul 5, 2017

Hi,

just wanted to add, that the same error occurs using django and django-q.

After some debugging i figured out that crash happens at this line pangocairo.pango_cairo_create_layout(ffi.cast( 'cairo_t *', self.dummy_context._pointer))
inside create_layout function at weasyprint/text.py

That's what @kgritesh wrote in #344 and it's exactly the same location where my script is failing. Unfortunately django-q doesn't nicely expose the resulting segfaults so I can't pitch in here.

If you need more information please just tell me. I'll try to look into the issue some more over the next few days

Regards,
Daniel

@liZe
Copy link
Member

liZe commented Nov 19, 2017

Could you try v0.41? f5367c8 may have fixed that.

@liZe
Copy link
Member

liZe commented Jan 29, 2018

If anyone hits this bug, I think that it's definitely closed by closing #566 (and #441 before). Feel free to reopen if you get this error with the current master branch!

@liZe liZe closed this as completed Jan 29, 2018
@sarathsunil
Copy link

sarathsunil commented Aug 8, 2018

I don't think this has anything to do with uWSGI, this is present in Windows 7 with Python27
pip install weasyprint
from weasyprint import HTML
ImportError: cannot import name properties

import weayprint
OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2

@liZe
Copy link
Member

liZe commented Aug 8, 2018

@sarathsunil Hello,

Thanks for your comment, but please don't add comments long after issues are closed, you're turning issues into zombies!

Your problem is explained in the documentation and in #589.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Problems preventing documents from being rendered
Projects
None yet
Development

No branches or pull requests

7 participants