Author tyoc
Recipients tyoc
Date 2009-05-02.19:49:54
SpamBayes Score 1.18239e-14
Marked as misclassified No
Message-id <1241293796.19.0.916040418837.issue5908@psf.upfronthosting.co.za>
In-reply-to
Content
Hi there, my problem is the following I dont know if this is a python 
error, spected behaviour or what, so here I go.

I'm using pyatspi in a console application for retrieve focus events
(you need to enable accessibility if want to check... that is at-spi-
registryd in 'top'):


Example 1: works correctly (focus events printed to stdout).
NOTE: See that the import is inside of 'run' and all the calls to the 
module are inside this thread.
FREEZE: No, correct behaviour.

[code start]--------------------------------------------
def cb(eve):
    print eve

import threading
class THRE4D(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        import pyatspi
        print 'spot 0'
        pyatspi.Registry.registerEventListener(cb, 'focus')
        import gobject
        print 'spot 1'
        gobject.timeout_add(5000, pyatspi.Registry.stop)
        print 'spot 2'
        pyatspi.Registry.start()
        print 'spot 3'

t = THRE4D()
t.start()
t.join(15000)
print 'joined'
[code end]--------------------------------------------

Example 2: it prints the first event and freeze quit because the 
timeout_add.
NOTE:See that I have moved the import and the register to __init__ the 
loop is in the new thread.
FREEZE: Yes. Print first event, dont know where it freeze (function), 
but has passed 'registerEventListener' and it has entered 
'Registry.start()'.

[code start]--------------------------------------------
def cb(eve):
    print eve

import threading
class THRE4D(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        import pyatspi
        pyatspi.Registry.registerEventListener(cb, 'focus')
    def run(self):
        import pyatspi
        print 'spot 0'
        import gobject
        print 'spot 1'
        gobject.timeout_add(5000, pyatspi.Registry.stop)
        print 'spot 2'
        pyatspi.Registry.start()
        print 'spot 3'

t = THRE4D()
t.start()
t.join(15000)
print 'joined'
[code end]--------------------------------------------

Example 3: It does not print any event at all and it freezes. It only 
prints 'spot 0'. The freeze is hard even that timeout_add doest end it 
in the time.
NOTE: See that I have only imported pyatspi in '__init__' all the calls 
are inside the thread.
FREEZE: Yes. No print of events, freeze inside inside 'accessible.py of 
pyatspi' in '_inner' where 'try: return func(self, *args, **kwargs)'.

[code start]--------------------------------------------
def cb(eve):
    print eve

import threading
class THRE4D(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        import pyatspi
    def run(self):
        import pyatspi
        print 'spot 0'
        pyatspi.Registry.registerEventListener(cb, 'focus')
        import gobject
        print 'spot 1'
        gobject.timeout_add(5000, pyatspi.Registry.stop)
        print 'spot 2'
        pyatspi.Registry.start()
        print 'spot 3'

t = THRE4D()
t.start()
t.join(15000)
print 'joined'
[code end]--------------------------------------------



actual conclusions

 * I dont know why importing it 2 times (pyatspi) in different context 
of threads launch this problem.

 * for a 'quick' solution: The import and the calls should be in the 
same thread "specially" 'registerEventListener'.
History
Date User Action Args
2009-05-02 19:49:56tyocsetrecipients: + tyoc
2009-05-02 19:49:56tyocsetmessageid: <1241293796.19.0.916040418837.issue5908@psf.upfronthosting.co.za>
2009-05-02 19:49:55tyoclinkissue5908 messages
2009-05-02 19:49:54tyoccreate