[Image-SIG] Threading patch for SANE module

Andrew M. Kuchling akuchlin@mems-exchange.org
Wed, 2 Jun 1999 12:42:39 -0400 (EDT)


Here's a small patch to Sane/_sanemodule.c, which allows other threads
to run while an image is being acquired.  I noticed this on the
microscope server, where there's an option to send lots of low-res
images while the stage is in motion.  Enabling this caused movements
to take 4 times as long, and I figured this was because the image
acquiring thread was taking all the CPU time; this starved the thread
that monitors the stage and terminates the first thread when the stage
stops.  The patch below helps a bit; I didn't add this to the .snap()
method because that method is pretty complicated, and I didn't want to
introduce a bug.

Also, I may have sent this before, but the following line should go
into Setup.in to show how to compile the SANE module.  (I've been
reinventing the line every time I do a fresh compile of PIL, which is
silly.)

#_sane Sane/_sanemodule.c -IlibImaging -L/usr/local/lib/sane/ -lsane-dll

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
Aristocrats need not be rich, but they must be free, and in the modern world
freedom grows rarer the more we prate about it.
    -- Robertson Davies, "Osbert Sitwell"


*** _sanemodule.c	1999/06/02 16:24:24	1.1
--- _sanemodule.c	1999/06/02 16:25:56
***************
*** 152,156 ****
--- 152,160 ----
        return NULL;
      }
+ 
+   Py_BEGIN_ALLOW_THREADS
    st=sane_start(self->h);
+   Py_END_ALLOW_THREADS
+ 
    if (st) return PySane_Error(st);
    Py_INCREF(Py_None);
***************
*** 170,174 ****
--- 174,182 ----
        return NULL;
      }
+ 
+   Py_BEGIN_ALLOW_THREADS
    sane_cancel(self->h);
+   Py_END_ALLOW_THREADS
+ 
    Py_INCREF(Py_None);
    return Py_None;