View | Details | Raw Unified | Return to bug 44806
Collapse All | Expand All

(-)a/management/python-notifier/python-notifier/ChangeLog (-1 / +1 lines)
 Lines 118-124    Link Here 
118
	* notifier/version.py: set version to 0.8.5
118
	* notifier/version.py: set version to 0.8.5
119
119
120
	* notifier/popen.py: when using Shell the command must not be
120
	* notifier/popen.py: when using Shell the command must not be
121
	split but passed as a string to the subprocess module
121
	splitted but passed as a string to the subprocess module
122
122
123
2010-06-15  Andreas Büsching  <crunchy@bitkipper.net>
123
2010-06-15  Andreas Büsching  <crunchy@bitkipper.net>
124
124
(-)a/management/python-notifier/python-notifier/README.md (-2 / +2 lines)
 Lines 168-174   shown in the following code snippet. Link Here 
168
	# within the object
168
	# within the object
169
	class Test2( object ):
169
	class Test2( object ):
170
		def __init__( self, test ):
170
		def __init__( self, test ):
171
			test.signals_connect( 'signal1', self._cb_signal )
171
			test.signal_connect( 'signal1', self._cb_signal )
172
172
173
		def _cb_signal( self, signal ):
173
		def _cb_signal( self, signal ):
174
			pass
174
			pass
 Lines 189-195   function as shown in the following snippet. Link Here 
189
	signals.emit( 'signal1', a, b )
189
	signals.emit( 'signal1', a, b )
190
190
191
	# within an object
191
	# within an object
192
	test.signals_emit( 'signal1', a, b, c )
192
	test.signal_emit( 'signal1', a, b, c )
193
193
194
The signature of the callback function for a signal depends on the
194
The signature of the callback function for a signal depends on the
195
specific signal provider, e.g. each signal may provide as many arguments
195
specific signal provider, e.g. each signal may provide as many arguments
(-)a/management/python-notifier/python-notifier/notifier/threads.py (-21 / +25 lines)
 Lines 26-32    Link Here 
26
26
27
import functools
27
import functools
28
import sys
28
import sys
29
import thread
29
import threading
30
import traceback
30
import traceback
31
31
32
__all__ = [ 'Simple' ]
32
__all__ = [ 'Simple' ]
 Lines 59-66   def __init__( self, name, function, callback ): Link Here 
59
		self._trace = None
59
		self._trace = None
60
		self._exc_info = None
60
		self._exc_info = None
61
		self._finished = False
61
		self._finished = False
62
		self._id = None
62
		self._thread = threading.Thread(target=self._run, name=self._name)
63
		self._lock = thread.allocate_lock()
63
		self._lock = threading.Lock()
64
		global _threads
64
		global _threads
65
		if not _threads:
65
		if not _threads:
66
			notifier.dispatcher_add( _simple_threads_dispatcher )
66
			notifier.dispatcher_add( _simple_threads_dispatcher )
 Lines 72-97   def __del__( self ): Link Here 
72
72
73
	def run( self ):
73
	def run( self ):
74
		"""Starts the thread"""
74
		"""Starts the thread"""
75
		self._id = thread.start_new_thread( self._run, () )
75
		self._thread.start()
76
76
77
	def _run( self ):
77
	def _run( self ):
78
		"""Encapsulates the given thread function to handle the return
78
		"""Encapsulates the given thread function to handle the return
79
		value in a thread-safe way and to catch exceptions raised from
79
		value in a thread-safe way and to catch exceptions raised from
80
		within it."""
80
		within it."""
81
		try:
81
		try:
82
			tmp = self._function()
82
			result = self._function()
83
			trace = None
83
			trace = None
84
			exc_info = None
84
			exc_info = None
85
		except BaseException, e:
85
		except BaseException as exc:
86
			exc_info = sys.exc_info()
86
			exc_info = sys.exc_info()
87
			trace = traceback.format_tb( sys.exc_info()[ 2 ] )
87
			trace = traceback.format_tb( sys.exc_info()[ 2 ] )
88
			tmp = e
88
			result = exc
89
		self._lock.acquire()
89
		self.lock()
90
		self._result = tmp
90
		try:
91
		self._trace = trace
91
			self._result = result
92
		self._exc_info = exc_info
92
			self._trace = trace
93
		self._finished = True
93
			self._exc_info = exc_info
94
		self._lock.release()
94
			self._finished = True
95
		finally:
96
			self.unlock()
95
97
96
	@property
98
	@property
97
	def result( self ):
99
	def result( self ):
 Lines 150-163   def _simple_threads_dispatcher(): Link Here 
150
152
151
	for task in _threads[ : ]:
153
	for task in _threads[ : ]:
152
		task.lock()
154
		task.lock()
153
		if task.finished:
155
		try:
154
			task.announce()
156
			if task.finished:
155
			_threads.remove( task )
157
				task.announce()
156
		elif hasattr( task, '_signals' ):
158
				_threads.remove( task )
157
			for signal, args in task._signals:
159
			elif hasattr( task, '_signals' ):
158
				task.signal_emit( signal, *args )
160
				for signal, args in task._signals:
159
			task._signals = []
161
					task.signal_emit( signal, *args )
160
		task.unlock()
162
				task._signals = []
163
		finally:
164
			task.unlock()
161
165
162
	return len( _threads ) > 0
166
	return len( _threads ) > 0
163
167

Return to bug 44806