/usr/share/opendict/lib/threads.py is in opendict 0.6.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #
# OpenDict
# Copyright (c) 2003-2006 Martynas Jocius <martynas.jocius@idiles.com>
# Copyright (c) 2007 IDILES SYSTEMS, UAB <support@idiles.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your opinion) any later version.
#
# This program is distributed in the hope that will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MECHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more detals.
#
# You shoud have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
#
# Module: threads
from threading import *
import sys
import os
import copy
import traceback
import string
class KThread(Thread):
"""Thread that can be killed during its run()"""
def join(self, timeout=None):
"""Kill it"""
Thread.join(self, timeout)
print "Thread killing himself"
#os._exit(0)
class Process:
def __init__(self, func, *param):
self.__done = 0
self.__result = None
self.__status = "working"
self.__C = Condition()
# Seperate thread
self.__T = Thread(target=self.Wrapper, args=(func, param))
self.__T.setName("ProcessThread")
self.__T.start()
def __repr__(self):
return "<Process at "+hex(id(self))+":"+self.__status+">"
def __call__(self):
self.__C.acquire()
while self.__done == 0:
self.__C.wait()
self.__C.release()
result = copy.copy(self.__result)
return result
def isDone(self):
return self.__done
def stop(self):
# FIXME: this actually doesn't kill the running process
# Needs to be done. Help?
#Thread.join(self.__T, None)
self.__T.join(0)
def Wrapper(self, func, param):
self.__C.acquire()
try:
self.__result = func(*param)
except:
self.__result = None
print string.join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1],
sys.exc_info()[2]), "")
self.__done = 1
self.__status = "self.__result"
self.__C.notify()
self.__C.release()
|