Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix http://code.google.com/p/python-lastfm/issues/detail?id=14 #7

Closed
wants to merge 2 commits into from

2 participants

alswl James Clarke
James Clarke
Owner
jc commented

As the Google code issue mentions it is not clear how this change will impact the library. Therefore I am reluctant to just merge this in because it works.

Having looked at the code in more detail it looks with _lock is to ensure the Api.FETCH_INTERVAL isn't exceeded within _read_url_data(). Removing the with _lock could result in exceeding the API limit.

Looking at the code path for authentication in more detail I see that _lock is used in set_session_key(). I think this is the source of the bug, that the _lock is locked by set_session_key() and then _read_url_data() attempts to get the lock but cannot and we end up deadlocked.

I'd be in favor of removing the with _lock from set_session_key().

alswl

I read the source again, and I agreed with you.

alswl alswl closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2012
  1. alswl

    fix http://code.google.com/p/python-lastfm/issues/detail?id=14 set_se…

    alswl authored
    …ssion_key will hang.
  2. alswl

    fix http://code.google.com/p/python-lastfm/issues/detail?id=14 set_se…

    alswl authored
    …ssion_key will hang.
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 8 deletions.
  1. +31 −0 .gitignore
  2. +7 −8 lastfm/api.py
31 .gitignore
View
@@ -0,0 +1,31 @@
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
+
+#myself
+tags
+README.html
15 lastfm/api.py
View
@@ -669,14 +669,13 @@ def _encode_parameters(self, parameters):
return urllib.urlencode([(k, self._encode(parameters[k])) for k in keys if parameters[k] is not None])
def _read_url_data(self, opener, url, data = None):
- with _lock:
- now = datetime.now()
- delta = now - self._last_fetch_time
- delta = delta.seconds*1000 + float(delta.microseconds)/1000
- if delta < Api.FETCH_INTERVAL:
- time.sleep((Api.FETCH_INTERVAL - delta)/1000)
- url_data = opener.open(url, data).read()
- self._last_fetch_time = datetime.now()
+ now = datetime.now()
+ delta = now - self._last_fetch_time
+ delta = delta.seconds*1000 + float(delta.microseconds)/1000
+ if delta < Api.FETCH_INTERVAL:
+ time.sleep((Api.FETCH_INTERVAL - delta)/1000)
+ url_data = opener.open(url, data).read()
+ self._last_fetch_time = datetime.now()
return url_data
@Wormhole.entrance('lfm-api-raw-data')
Something went wrong with that request. Please try again.