2
# -*- coding: utf-8 -*-
3
#A part of NonVisual Desktop Access (NVDA)
4
#Copyright (C) 2006-2010 NVDA Contributors <http://www.nvda-project.org/>
5
#Copyright (C) 2010-2012 Takuya Nishimoto (nishimotz.com)
6
#This file is covered by the GNU General Public License.
7
#See the file COPYING for more details.
9
# based on NVDA (synthDrivers/_espeak.py)
11
from logHandler import log
19
class BgThread(threading.Thread):
21
threading.Thread.__init__(self)
27
func, args, kwargs = bgQueue.get()
33
log.error("Error running function from queue", exc_info=True)
36
def execWhenDone(func, *args, **kwargs):
38
# This can't be a kwarg in the function definition because it will consume the first non-keywor dargument which is meant for func.
39
mustBeAsync = kwargs.pop("mustBeAsync", False)
40
if mustBeAsync or bgQueue.unfinished_tasks != 0:
41
# Either this operation must be asynchronous or There is still an operation in progress.
42
# Therefore, run this asynchronously in the background thread.
43
bgQueue.put((func, args, kwargs))
48
global bgThread, bgQueue
49
bgQueue = Queue.Queue()
54
global bgThread, bgQueue
55
bgQueue.put((None, None, None))