[python-imaging-sane] get_devices and threading

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[python-imaging-sane] get_devices and threading

Sandro Mani
Hi,
I wanted to execute sane.get_devices in a separate thread, i.e. consider
the following program:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import threading
import sane
import time

devices=None

class GetDevicesThread(threading.Thread):
     def __init__(self):
         threading.Thread.__init__(self)
         self.setDaemon(True)

     def run(self):
         global devices
         #time.sleep(10)
         #devices=[]
         devices=sane.get_devices()

sane.init()
GetDevicesThread().start()
print "Detecting devices"
while devices==None:
     time.sleep(1)
     print "."
print devices

The devices=sane.get_devices() call in run() for some reason pauses the
main thread during it's execution - if I switch the statement with the
two commented lines above, all works as expected. Is there any
particular reason for this behaviour?
Thanks
Sandro Mani
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: [python-imaging-sane] get_devices and threading

Edward Cannon
wrong mailing list, this is for PIL and related topics only. Try a
sane specific mailing list

On Mon, Dec 27, 2010 at 8:58 AM, Sandro Mani <[hidden email]> wrote:

> Hi,
> I wanted to execute sane.get_devices in a separate thread, i.e. consider the
> following program:
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> import threading
> import sane
> import time
>
> devices=None
>
> class GetDevicesThread(threading.Thread):
>    def __init__(self):
>        threading.Thread.__init__(self)
>        self.setDaemon(True)
>
>    def run(self):
>        global devices
>        #time.sleep(10)
>        #devices=[]
>        devices=sane.get_devices()
>
> sane.init()
> GetDevicesThread().start()
> print "Detecting devices"
> while devices==None:
>    time.sleep(1)
>    print "."
> print devices
>
> The devices=sane.get_devices() call in run() for some reason pauses the main
> thread during it's execution - if I switch the statement with the two
> commented lines above, all works as expected. Is there any particular reason
> for this behaviour?
> Thanks
> Sandro Mani
> _______________________________________________
> Image-SIG maillist  -  [hidden email]
> http://mail.python.org/mailman/listinfo/image-sig
>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: [python-imaging-sane] get_devices and threading

Fredrik Lundh
Well, I'd say scanning falls under the "image stuff" umbrella, and the
Sane bindings are shipped with the PIL source code...  I don't know
much about them, though, but I suspect this is a Python GIL issue.

</F>

2010/12/28 Edward Cannon <[hidden email]>:

> wrong mailing list, this is for PIL and related topics only. Try a
> sane specific mailing list
>
> On Mon, Dec 27, 2010 at 8:58 AM, Sandro Mani <[hidden email]> wrote:
>> Hi,
>> I wanted to execute sane.get_devices in a separate thread, i.e. consider the
>> following program:
>>
>> #!/usr/bin/env python
>> # -*- coding: utf-8 -*-
>>
>> import threading
>> import sane
>> import time
>>
>> devices=None
>>
>> class GetDevicesThread(threading.Thread):
>>    def __init__(self):
>>        threading.Thread.__init__(self)
>>        self.setDaemon(True)
>>
>>    def run(self):
>>        global devices
>>        #time.sleep(10)
>>        #devices=[]
>>        devices=sane.get_devices()
>>
>> sane.init()
>> GetDevicesThread().start()
>> print "Detecting devices"
>> while devices==None:
>>    time.sleep(1)
>>    print "."
>> print devices
>>
>> The devices=sane.get_devices() call in run() for some reason pauses the main
>> thread during it's execution - if I switch the statement with the two
>> commented lines above, all works as expected. Is there any particular reason
>> for this behaviour?
>> Thanks
>> Sandro Mani
>> _______________________________________________
>> Image-SIG maillist  -  [hidden email]
>> http://mail.python.org/mailman/listinfo/image-sig
>>
> _______________________________________________
> Image-SIG maillist  -  [hidden email]
> http://mail.python.org/mailman/listinfo/image-sig
>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig