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.:
我们在芹菜下面用Python棒处理很多图片。在我们的一些服务器上,我们的处理有时会留下很多临时文件,例如:
$ 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 [...]
$ ls lh / tmp / - - - - - - - - 1 ubuntu ubuntu 1.9 m 4月1日04:35 magick-y1yKKiVZ - - - - - - - - 1 ubuntu ubuntu 1.9 m 4月1 04:41 magick-Y22P6McK - - - - - - - - 1 ubuntu ubuntu 1.9 m 4月1 04:37 magick-YaaSIYrk - - - - - - - - 1 ubuntu ubuntu 1.9 m 4月1 04:39 magick-YEkn4H15 - - - - - - - - 1 ubuntu ubuntu 1.9 m 4月1 04:39 magick-yf2Vrfwi - - - - - - - - 1 ubuntu ubuntu 1.9 m 4月1 04:38 magick-YIYTaArn - - - - - - - - 199 k 4月1 ubuntu ubuntu有magick-YLM5wYm9 - - - - - - - - 199 k 4月1 ubuntu ubuntu有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?
有没有一种方法可以让魔杖在处理一些文件后清理掉?如果它是预期的行为,是否有一种方法来调试它,并通过放置一个日志语句,知道哪个映像创建了哪个temp文件?
Thanks
谢谢
1 个解决方案
#1
2
Easy way: In your environment settings point MAGICK_TMPDIR=/home/somewhere
and rm magick-*
that folder in your crontab.
简单方法:在您的环境设置中,指向MAGICK_TMPDIR=/home/somewhere和rm magick-* crontab中的文件夹。
Hard way: Apply this path to ImageMagick before compiling:
硬方法:在编译之前将此路径应用于ImageMagick:
--- 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);
}
#1
2
Easy way: In your environment settings point MAGICK_TMPDIR=/home/somewhere
and rm magick-*
that folder in your crontab.
简单方法:在您的环境设置中,指向MAGICK_TMPDIR=/home/somewhere和rm magick-* crontab中的文件夹。
Hard way: Apply this path to ImageMagick before compiling:
硬方法:在编译之前将此路径应用于ImageMagick:
--- 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);
}