-
-
Notifications
You must be signed in to change notification settings - Fork 704
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
Crashed when using celery to execute Weasyprint tasks #684
Comments
Thanks for reporting the issue. It's probably the same problem as #167, and I honestly don't know how to fix it. Is it possible for you to get a stack trace? I suppose that the crash happens in C code (probably with Pango or Cairo).
It's not designed to crash with multiple threads, but it's not designed to be thread-safe neither. Cairo is supposed to be thread-safe (see https://gitlab.freedesktop.org/cairo/cairo/issues/266) and I've been using WeasyPrint on multiprocess environments with uWSGI for years, so I suppose it somehow works.
Just as in #167, you're on macOS. Maybe there's something wrong with Cairo or Pango on macOS… |
Thank you for reply. And I finally solve this problem by using Eventlet concurrency in Celery and it works fine. I think it crashed because of the multi-process issues in which the default Celery concurrency used. And Mac has a strict protection for multi-process resource sharing. When I using Eventlet, it use green threads instead of prefork pool and the OS protection for processes is ignored. And the Celery tasks work fine. Thank you for your help! |
No problem. We can assume that we can't do anything about this … unless some macOS guru comes and explains what is going on. Until then, I think that we can safely close this issue. |
I'm using the latest version of celery (5+) and weasyprint as of September 2021, and I'm seeing a similar issue. I'm getting segmentation fault errors if I try to call new instances of weasyprint in separate celery tasks. I tried every which way to refactor how my tasks were structured to no avail, so I thought to switch from a prefork worker pool to a gevent pool in my celery worker, which has helped me get around threading issues in the past with celery. The segmentation fault went away and I'm now calling weasyprint successfully from my tasks. I'll be honest, like @liZe, I don't really understand why this error is occurring with a prefork pool, but I don't really have the time or appetite to debug it and switching to a gevent pool solved my problem for now. Perhaps this will help someone else. |
Hi:
I'm using Weasyprint to generate PDFs in celery tasks. And it crashed with trace logs below:
After investigation, I found the issue:
In my task code, I have imported a module which import WeasyPrint at the top of code, and when celery execute the task, it crashed because Celery execute WeasyPrint in another process, which cause the multi-processing or thread issues. So I imported WeasyPrint lib inside the method executed instead of the whole module.
Is this a thread-safety design for you, or it can be fixed since async execute for PDF generation is really common-used?
Thanks,
The text was updated successfully, but these errors were encountered: