Python Wand generates lots of temporary files
Asked Answered
A

1

10

We use Python Wand under Celery to process a lot of pictures. On some of our servers, our treatment sometimes leaves a lot of temporary files behind, e.g.:

$ ls -lh /tmp/ -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:35 magick-y1yKKiVZ -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:41 magick-Y22P6McK -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:37 magick-YaaSIYrk -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:39 magick-YEkn4H15 -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:39 magick-yf2Vrfwi -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:38 magick-YIYTaArn -rw------- 1 ubuntu ubuntu 199K Apr 1 04:43 magick-YLM5wYm9 -rw------- 1 ubuntu ubuntu 199K Apr 1 04:43 magick-YLo5SeVp [...]

Is there a way to make Wand clean up after it worked on some file? If it's the expected behavior, is there a way to debug this and know which image created which temp file, by putting a log statement for example?

Thanks

Annunciate answered 1/4, 2014 at 4:46 Comment(1)
It is not the expected behavior, and done by ImageMagick, not Wand.Allineallis
F
2

Easy way: In your environment settings point MAGICK_TMPDIR=/home/somewhere and rm magick-* that folder in your crontab.

Hard way: Apply this path to ImageMagick before compiling:

--- pristine/imagemagick-6.5.7.8/magick/resource.c 2009-10-26 16:52:10.000000000 +0300
+++ libm/imagemagick-6.5.7.8/magick/resource.c 2010-09-28 19:18:39.000000000 +0400
@@ -329,6 +329,7 @@
 static void *DestroyTemporaryResources(void *temporary_resource)
 {
   (void) remove((char *) temporary_resource);
+ RelinquishMagickMemory(temporary_resource);
   return((void *) NULL);
 }

@@ -474,10 +475,10 @@
   (void) LockSemaphoreInfo(resource_semaphore);
   if (temporary_resources == (SplayTreeInfo *) NULL)
     temporary_resources=NewSplayTree(CompareSplayTreeString,
- RelinquishMagickMemory,DestroyTemporaryResources);
+ DestroyTemporaryResources, NULL);
   (void) UnlockSemaphoreInfo(resource_semaphore);
   resource=ConstantString(path);
- (void) AddValueToSplayTree(temporary_resources,resource,resource);
+ (void) AddValueToSplayTree(temporary_resources,resource,NULL);
   return(file);
 }
Fates answered 11/6, 2014 at 20:40 Comment(1)
Hi Farsheed, how do I do it? tksChemosynthesis

© 2022 - 2024 — McMap. All rights reserved.