* fixed: crashes when adding a job to Asynchronizer and starting it when it already started.

This commit is contained in:
Amr Hassan 2008-09-12 15:49:13 +00:00
parent ace8109ad7
commit 7e203ee5a2
3 changed files with 30 additions and 12 deletions

View file

@ -1,3 +1,6 @@
0.2b9
* fixed: crashes when adding a job to Asynchronizer and starting it when it already started.
0.2b8
* Asynchronizer.async_call now accepts None as callback.
* moved all the tag related functions to a separate Taggable class.

View file

@ -22,7 +22,7 @@
# documentation at http://code.google.com/p/pylast/wiki/Documentation
LIB_NAME = 'pyLast'
LIB_VERSION = '0.2b8'
LIB_VERSION = '0.2b9'
API_SERVER = 'ws.audioscrobbler.com'
API_SUBDIR = '/2.0/'
@ -122,20 +122,32 @@ class Asynchronizer(threading.Thread):
self._calls = {} #calls is structured like this: {call_pointer: (arg1, arg2, ...)}
self._callbacks = {} #callbacks is structred like this: {call_pointer: callback_pointer}
self.is_running = False
def isRunning(self):
"""Returns if the thread is already running, for usage instead of isAlive which doesn't believe in thread restarting."""
return self.is_running
def run(self):
"""Avoid running this function. Use start() to begin the thread's work."""
for call in self._calls.keys():
output = call(*(self._calls[call]))
callback = self._callbacks[call]
if callback: #callback can be None if not wanted
callback(self, output)
del self._calls[call]
del self._callbacks[call]
self.is_running = True
while len(self._calls):
for call in self._calls.keys():
output = call(*(self._calls[call]))
callback = self._callbacks[call]
if callback: #callback can be None if not wanted
callback(self, output)
del self._calls[call]
del self._callbacks[call]
self.is_running = False
def async_call(self, callback, call, *call_args):
"""This is the function for setting up an asynchronous operation.
@ -150,6 +162,9 @@ class Asynchronizer(threading.Thread):
def start(self):
"""Since that Python thread objects can only be started once. This is my little work-around."""
if self.isRunning():
return
threading.Thread.__init__(self)
super(Asynchronizer, self).start()

View file

@ -1,7 +1,7 @@
from distutils.core import setup
setup(name='pylast',
version='0.2b8',
version='0.2b9',
author='Amr Hassan',
long_description = 'Python bindings for the Last.fm API 2.0',
author_email='amr.hassan@gmail.com',