New submission from tyoc <z...@alum.com>: 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'. ---------- components: Library (Lib), None messages: 86975 nosy: tyoc severity: normal status: open title: I need to import the module in the same thread? type: behavior versions: Python 2.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue5908> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com