Forums

Wand package in Wagtail not working

Hi everyone!

I am trying to implement GIF support in my Wagtail (v2.2.2) project on Pythonanywhere (according to the documentation on https://docs.wagtail.io/en/v2.2.2/advanced_topics/images/animated_gifs.html), but for some reason, after installing Wand, when visiting a page both in the Admin and the Front-end that contains a GIF image, I get a server error.

I've tried installing wand versions 0.5.1, 0.5.0, and 0.4.4, but I always get that server error.

When wand is uninstalled, the app works as expected.

According to the docs, Wand needs ImageMagick to work properly.

Does Pythonanywhere have the necessary packages installed to accomplish this task (implementing GIF support in wagtail), or is something missing?

Thanks in advance.

ImageMagick is definitely installed. Did you check the error log when you were getting server errors? There's a link to the log on the "Web" tab, and each server error that you see on your site will dump a full traceback there. The most recent error will be at the bottom of the file.

I realized that Wand 0.4.4 was installed outside the virtualenv, so I installed the same version in the virtual env to avoid problems, but the problem remains.

The page takes forever to load and when it does, I get the error:

File "/home/diogomakes/.virtualenvs/personal_site_env/lib/python3.6/site-packages/wand/resource.py", line 222, in raise_exception
raise e
wand.exceptions.CacheError: unable to read pixel cache `/tmp/magick-212ZLyXqjfQYYm': Disk quota exceeded @ error/cache.c/ReadPixelCachePixels/4502

Also, in one of the tries, I got a pythonanywhere page telling me to mention this other error:

Error code: 504-loadbalancer

These errors make sense since, for some reason, the memory keeps filing while I try to load the page with the GIF image.

I keep emptying the tmp folder, but with only 34% of my storage occupied, I think Wand should have more than enough memory to process the images.

At this point, I doubt it is a problem I can fix on my side...

Your file storage is at 100% full, not 34%. That's what is causing the quota exception and that's what's breaking the web app.

Well, then there's something fishy going on, since I've emptied the tmp folder countless times, lowering the storage to 34% and it seems to be filing from nowhere (even without me using the app).

Is there a way we can figure out what's really filing the storage so quickly?

I've emptied the tmp folder again with rm -rf /tmp/*, so it should be at around 34% again.

You can use the instructions here to determine where the files are and then look at their names to try to work out what might be creating them. In some cases, perhaps you can look at the contents to see where they came from.

Same issue as before, but slightly different error :(

wand.exceptions.CacheError: unable to read pixel cache `/tmp/magick-21BJnTAn42o3ny': Stale file handle @ error/cache.c/ReadPixelCachePixels/4502
2019-03-13 14:18:05,280: OSError: write error

But this time, I got the same errors at 61% of storage usage.

I really didn't want to ask for this, but would you be so kind as to try and installing Wagtail 2.2.2 on a test account and implementing animated GIF support and see if you can figure out how to do this.

I know you guys are probably very busy so I understand if this is too big of a request.

But if this problem continues, I'll be obligated to migrate my project to another host (which I really want to avoid).

Anyway, thanks for your time!

It just sounds like Wand is dumping a lot of files into /tmp. Try to work out if something in your code is causing it and see if you can get it to clean up after itself.

I wish it was that simple, but my code doesn't use Wand at all.

It's Wagtail's code that has Wand as a dependency to load GIF images.

Implementing GIF support should be as easy as installing Wand and ImageMagick (https://docs.wagtail.io/en/v2.2.2/advanced_topics/images/animated_gifs.html).

According to this, the issue might really be in ImageMagick: https://github.com/wagtail/wagtail/issues/2505

But as far as I know, Pythonanywhere users aren't allowed to modify system libraries/packages/apps (I've tried and got a permission error).

In fact, can you guys install/upgrade it for me?

Following these instructions should work: http://docs.wand-py.org/en/0.4.2/guide/install.html

I would very much appreciate your help on this (and other wagtail users as well).

I don't think the problem is the version of ImageMagick -- that bug report dates back to 2016, and we have reasonably recent (eg. more recent than then) versions of all of the dependencies they mention.

I see your site is up and running at the moment and hasn't generated any errors since yesterday at around 14:18 -- have you made any changes? Or have you just switched GIF support off temporarily?

Right now, I do have Wand installed, but I still can't access any page containing GIf images. All other pages work fine.

All errors I've seen are either related to Wand consuming too much memory, or OS permission errors.

I've started trying to solve the problem by figuring out an alternative solution to loading GIFs, but due to the lack of help on Wagtail's programmer's part and the complexity of the source code, I wasn't able to figure out an effective, fast solution.

I am running a business here and having this implemented is fundamental for my end user's experience.

I am not a professional programmer, so I don't care what kind of solution I find as long as it works.

I was looking at implementing this solution from scratch on Django, but it would just take me too long to figure out how to integrate it with Wagtail (not to mention the lack of documentation), so you guys are my last hope of getting this to work.

If I can't on Pythonanywhere, then I'll have to go through the hassle of setting up my project on a different host (which is no easy task for a non-professional coder - I needed about two days to get this one to work properly here).

Even though setting up my project on Pythonanywhere was a rather challenging task, I am very grateful for your support and patience.

Actually... can you guys tell me if in theory having Wand outside the virtualenv translates to having it inside the virtualenv? Maybe the problem is having Wand twice.

Or are virtualenv's packages completely independent?

Is there a way to not use the virtualenv altogether?

The install of Wand in a virtualenv is isolated from any other install of Wand. In general, using a virtualenv is a good idea because of the isolation they provide from the system packages.

OK, at this point I am pretty sure I found the problem.

According to this thread: https://github.com/wagtail/wagtail/issues/3575 , many other people are having the exact same issue as me without any solution at sight.

The last post seems pretty recent, so this time we are looking at a current situation.

In conclusion: Wand's memory issues are probably due to the fact that Wagtail's developers didn't quite code the animated GIF support well, giving rise to memory leaking issues and not allowing for an easy patch on the Wagtail users/developers part apart from changing the actual source code of Wagtail which would take quite a bit of time.

It's quite sad that they went as far as successfully loading animated GIFs in the Admin Images section, but messing up all other attempts of loading GIFs (even though this is the simplest thing in the world considering the GIF file is already in the server and we just need to load it in the template file).

Anyway... Thanks for all the help @glenn and @giles, I really appreciate your patience with this!

Ah. That's a bit disappointing. Sorry we couldn't find a solution for you.