* fixed: crashes when adding a job to Asynchronizer and starting it when it already started.
This commit is contained in:
parent
ace8109ad7
commit
7e203ee5a2
|
@ -1,3 +1,6 @@
|
||||||
|
0.2b9
|
||||||
|
* fixed: crashes when adding a job to Asynchronizer and starting it when it already started.
|
||||||
|
|
||||||
0.2b8
|
0.2b8
|
||||||
* Asynchronizer.async_call now accepts None as callback.
|
* Asynchronizer.async_call now accepts None as callback.
|
||||||
* moved all the tag related functions to a separate Taggable class.
|
* moved all the tag related functions to a separate Taggable class.
|
||||||
|
|
31
pylast.py
31
pylast.py
|
@ -22,7 +22,7 @@
|
||||||
# documentation at http://code.google.com/p/pylast/wiki/Documentation
|
# documentation at http://code.google.com/p/pylast/wiki/Documentation
|
||||||
|
|
||||||
LIB_NAME = 'pyLast'
|
LIB_NAME = 'pyLast'
|
||||||
LIB_VERSION = '0.2b8'
|
LIB_VERSION = '0.2b9'
|
||||||
|
|
||||||
API_SERVER = 'ws.audioscrobbler.com'
|
API_SERVER = 'ws.audioscrobbler.com'
|
||||||
API_SUBDIR = '/2.0/'
|
API_SUBDIR = '/2.0/'
|
||||||
|
@ -123,19 +123,31 @@ class Asynchronizer(threading.Thread):
|
||||||
self._calls = {} #calls is structured like this: {call_pointer: (arg1, arg2, ...)}
|
self._calls = {} #calls is structured like this: {call_pointer: (arg1, arg2, ...)}
|
||||||
self._callbacks = {} #callbacks is structred like this: {call_pointer: callback_pointer}
|
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):
|
def run(self):
|
||||||
"""Avoid running this function. Use start() to begin the thread's work."""
|
"""Avoid running this function. Use start() to begin the thread's work."""
|
||||||
|
|
||||||
for call in self._calls.keys():
|
self.is_running = True
|
||||||
|
|
||||||
output = call(*(self._calls[call]))
|
while len(self._calls):
|
||||||
callback = self._callbacks[call]
|
for call in self._calls.keys():
|
||||||
|
|
||||||
if callback: #callback can be None if not wanted
|
output = call(*(self._calls[call]))
|
||||||
callback(self, output)
|
callback = self._callbacks[call]
|
||||||
|
|
||||||
del self._calls[call]
|
if callback: #callback can be None if not wanted
|
||||||
del self._callbacks[call]
|
callback(self, output)
|
||||||
|
|
||||||
|
del self._calls[call]
|
||||||
|
del self._callbacks[call]
|
||||||
|
|
||||||
|
self.is_running = False
|
||||||
|
|
||||||
def async_call(self, callback, call, *call_args):
|
def async_call(self, callback, call, *call_args):
|
||||||
"""This is the function for setting up an asynchronous operation.
|
"""This is the function for setting up an asynchronous operation.
|
||||||
|
@ -150,6 +162,9 @@ class Asynchronizer(threading.Thread):
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Since that Python thread objects can only be started once. This is my little work-around."""
|
"""Since that Python thread objects can only be started once. This is my little work-around."""
|
||||||
|
|
||||||
|
if self.isRunning():
|
||||||
|
return
|
||||||
|
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
super(Asynchronizer, self).start()
|
super(Asynchronizer, self).start()
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -1,7 +1,7 @@
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
setup(name='pylast',
|
setup(name='pylast',
|
||||||
version='0.2b8',
|
version='0.2b9',
|
||||||
author='Amr Hassan',
|
author='Amr Hassan',
|
||||||
long_description = 'Python bindings for the Last.fm API 2.0',
|
long_description = 'Python bindings for the Last.fm API 2.0',
|
||||||
author_email='amr.hassan@gmail.com',
|
author_email='amr.hassan@gmail.com',
|
||||||
|
|
Loading…
Reference in a new issue