Author: dmeyer
Date: Fri Jan 18 14:56:38 2008
New Revision: 2981
Log:
replace code using kaa.Thread with kaa.ThreadCallback
Modified:
trunk/base/API_CHANGES.txt
trunk/base/src/notifier/__init__.py
trunk/base/src/notifier/sockets.py
trunk/base/src/notifier/thread.py
trunk/base/src/notifier/url.py
trunk/beacon/bin/beacon-mount
trunk/epg/test/vdr.py
trunk/popcorn/src/backends/mplayer/player.py
Modified: trunk/base/API_CHANGES.txt
==============================================================================
--- trunk/base/API_CHANGES.txt (original)
+++ trunk/base/API_CHANGES.txt Fri Jan 18 14:56:38 2008
@@ -22,4 +22,9 @@
Callback. In most cases ThreadCallback was not used directly so
this API change should not break some code.
+4. Renamed Thread to ThreadCallback. The class has no signals anymore
+ and the start function is now __call__ and it will return an
+ InProgress object
+
+
Modified: trunk/base/src/notifier/__init__.py
==============================================================================
--- trunk/base/src/notifier/__init__.py (original)
+++ trunk/base/src/notifier/__init__.py Fri Jan 18 14:56:38 2008
@@ -32,7 +32,7 @@
from popen import Process
from callback import Callback, WeakCallback, Signal, Signals
-from thread import MainThreadCallback, ThreadCallback, Thread, is_mainthread
+from thread import MainThreadCallback, ThreadCallback, is_mainthread
from timer import Timer, WeakTimer, OneShotTimer, WeakOneShotTimer, AtTimer,
OneShotAtTimer
from sockets import SocketDispatcher, WeakSocketDispatcher, Socket, IO_READ,
IO_WRITE
from event import Event, EventHandler, WeakEventHandler
@@ -44,7 +44,7 @@
# Here's what will be imported into the kaa namespace.
__all__ = [
'Process', 'Callback', 'WeakCallback', 'Signal', 'Signals',
'MainThreadCallback',
- 'Thread', 'Timer', 'WeakTimer', 'OneShotTimer', 'WeakOneShotTimer',
'AtTimer',
+ 'Timer', 'WeakTimer', 'OneShotTimer', 'WeakOneShotTimer', 'AtTimer',
'OneShotAtTimer', 'SocketDispatcher', 'WeakSocketDispatcher', 'Socket',
'IO_READ', 'IO_WRITE', 'Event', 'EventHandler', 'WeakEventHandler',
'YieldContinue', 'YieldCallback', 'YieldFunction', 'NamedThreadCallback',
Modified: trunk/base/src/notifier/sockets.py
==============================================================================
--- trunk/base/src/notifier/sockets.py (original)
+++ trunk/base/src/notifier/sockets.py Fri Jan 18 14:56:38 2008
@@ -38,7 +38,7 @@
import nf_wrapper as notifier
from callback import Callback, Signal
-from thread import MainThreadCallback, Thread, is_mainthread
+from thread import MainThreadCallback, ThreadCallback, is_mainthread
# get logging object
log = logging.getLogger('notifier')
@@ -175,16 +175,14 @@
self._make_socket(addr)
- thread = Thread(self._connect_thread)
+ in_progress = ThreadCallback(self._connect_thread)()
result_holder = []
if not async:
cb = Callback(lambda res, x: x.append(res), result_holder)
else:
cb = self.signals["connected"].emit
-
- thread.signals["completed"].connect(cb)
- thread.signals["exception"].connect(cb)
- thread.start()
+ in_progress.connect(cb)
+ in_progress.exception_handler.connect(cb)
if async != None:
return
Modified: trunk/base/src/notifier/thread.py
==============================================================================
--- trunk/base/src/notifier/thread.py (original)
+++ trunk/base/src/notifier/thread.py Fri Jan 18 14:56:38 2008
@@ -46,7 +46,7 @@
#
# -----------------------------------------------------------------------------
-__all__ = [ 'MainThreadCallback', 'ThreadCallback', 'Thread', 'is_mainthread',
+__all__ = [ 'MainThreadCallback', 'ThreadCallback', 'is_mainthread',
'wakeup', 'set_as_mainthread' ]
# python imports
@@ -204,73 +204,6 @@
-class Thread(threading.Thread):
- """
- Notifier aware wrapper for threads. When a thread is started, it is
- impossible to fork the current process into a second one without exec both
- using the notifier main loop because of the shared _thread_notifier_pipe.
- """
- def __init__(self, function, *args, **kargs):
- threading.Thread.__init__(self)
- self.function = function
- self.args = args
- self.kargs = kargs
-
- self.signals = {
- "completed": Signal(),
- "exception": Signal()
- }
-
-
- def wait_on_exit(self, wait=False):
- """
- Wait for the thread on application exit. Default is True.
- """
- self.setDaemon(not wait)
-
-
- def _emit_and_join(self, signal, arg):
- """
- Run callback signals and join dead thread.
- """
- self.signals[signal].emit(arg)
- if self != threading.currentThread():
- # Only join if we're not the current thread (i.e. mainthread).
- self.join()
-
-
- def start(self):
- """
- Start the thread and return an InProgress object.
- """
- r = InProgress()
- self.signals['completed'].connect_once(r.finished)
- self.signals['exception'].connect_once(r.exception)
- super(Thread, self).start()
- return r
-
-
- def run(self):
- """
- Call the function and store the result
- """
- try:
- # run thread function
- result = self.function(*self.args, **self.kargs)
- MainThreadCallback(self._emit_and_join, "completed", result)()
- except:
- log.exception('Thread raised exception:')
- MainThreadCallback(self._emit_and_join, "exception",
sys.exc_info()[1])()
-
-
- def is_running(self):
- """
- Returns True if the thread is running, False otherwise.
- """
- # We just wrap isAlive().
- return self.isAlive()
-
-
def is_mainthread():
"""
Return True if the caller is in the main thread right now.
Modified: trunk/base/src/notifier/url.py
==============================================================================
--- trunk/base/src/notifier/url.py (original)
+++ trunk/base/src/notifier/url.py Fri Jan 18 14:56:38 2008
@@ -46,7 +46,7 @@
import urllib2
# kaa.notifier imports
-from kaa.notifier import Thread, Signals, InProgress
+from kaa.notifier import ThreadCallback, Signals, InProgress
# add password manager to urllib
pm = urllib2.HTTPPasswordMgrWithDefaultRealm()
@@ -63,7 +63,7 @@
"""
def __init__(self, request, data = None):
self._args = request, data
- self.signals = Signals('header', 'data', {'completed': InProgress() })
+ self.signals = Signals('header', 'data')
def fetch(self, length=0):
@@ -75,14 +75,9 @@
The function returns the 'completed' signal which is an InProgress
object.
"""
- t = Thread(self._fetch_thread, length)
- signal = self.signals['completed']
- t.signals['completed'].connect_once(signal.finished)
- t.signals['exception'].connect_once(signal.exception)
- t.start()
- # FIXME: Thread should return this by default and not the two
- # independed signals
- return signal
+ t = ThreadCallback(self._fetch_thread, length)
+ t.wait_on_exit(False)
+ return t()
def _fetch_thread(self, length):
@@ -147,9 +142,9 @@
url = url[:8+url[8:].find('/')] + \
urllib.quote(url[8+url[8:].find('/'):])
s = InProgress.Progress()
- t = Thread(download, url, filename, tmpname, s)
+ t = ThreadCallback(download, url, filename, tmpname, s)
t.wait_on_exit(False)
- async = t.start()
+ async = t()
async.set_status(s)
return async
Modified: trunk/beacon/bin/beacon-mount
==============================================================================
--- trunk/beacon/bin/beacon-mount (original)
+++ trunk/beacon/bin/beacon-mount Fri Jan 18 14:56:38 2008
@@ -148,8 +148,7 @@
# FIXME: should only daemonize when we know fs is mounted.
kaa.utils.daemonize(stdout = logfile)
- thread = kaa.Thread(fs.main)
- thread.signals["exception"].connect(lambda dummy: kaa.main.stop())
- thread.start()
+ thread = kaa.ThreadCallback(fs.main)
+ thread().exception_handler.connect(lambda dummy: kaa.main.stop())
kaa.main.run()
Modified: trunk/epg/test/vdr.py
==============================================================================
--- trunk/epg/test/vdr.py (original)
+++ trunk/epg/test/vdr.py Fri Jan 18 14:56:38 2008
@@ -144,8 +144,5 @@
host=None, port=None, access_by='sid', limit_channels=''):
log.debug('update')
- thread = kaa.Thread(_update_data_thread, epg, vdr_dir,
- channels_file, epg_file, host, port,
access_by,
- limit_channels)
- thread.start()
-
+ kaa.ThreadCallback(_update_data_thread, epg, vdr_dir, channels_file,
+ epg_file, host, port, access_by, limit_channels)()
Modified: trunk/popcorn/src/backends/mplayer/player.py
==============================================================================
--- trunk/popcorn/src/backends/mplayer/player.py (original)
+++ trunk/popcorn/src/backends/mplayer/player.py Fri Jan 18 14:56:38 2008
@@ -89,12 +89,11 @@
# We need to run MPlayer to get these values. Create a signal,
# call ourself as a thread, and return the signal back to the
# caller.
- thread = kaa.Thread(_get_mplayer_info, path, None, mtime)
- # Thread class ensures the callbacks get invoked in the main
+ async = kaa.ThreadCallback(_get_mplayer_info, path, None, mtime)()
+ # ThreadCallback class ensures the callbacks get invoked in the
main
# thread.
- thread.signals["completed"].connect(callback)
- thread.signals["exception"].connect(callback)
- thread.start()
+ async.connect(callback)
+ async.exception_handler.connect(callback)
return None
# At this point we're running in a thread.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog