-
-
Notifications
You must be signed in to change notification settings - Fork 93
'_lock' is not defined on exit when using python 3 #133
Comments
Same here. Python 3.4.1 though. |
This is probably some issue with the order objects are garbage collected on Python shutdown. |
Same here, on python 3.4: In [1]: import spotify
In [2]: session = spotify.Session()
In [3]: exit
Exception ignored in: <function GcWeakrefs.__init__.<locals>.remove at 0x7febf5367950>
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/cffi/gc_weakref.py", line 12, in remove
File "/usr/local/lib/python3.4/dist-packages/spotify/__init__.py", line 57, in wrapper
NameError: name '_lock' is not defined |
I started looking closer at this issue a while back. IIRC, I managed to reduce how often this happened, but not to get rid of it totally. As a sign of how late in the interpreter shutdown this exception is raised, the following change does not hide the error as you would expect, but cause a diff --git a/spotify/__init__.py b/spotify/__init__.py
index 857bc84..1327d46 100644
--- a/spotify/__init__.py
+++ b/spotify/__init__.py
@@ -56,8 +56,11 @@ def serialized(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
- with _lock:
- return f(*args, **kwargs)
+ try:
+ with _lock:
+ return f(*args, **kwargs)
+ except NameError:
+ pass
if not hasattr(wrapper, '__wrapped__'):
# Workaround for Python < 3.2
wrapper.__wrapped__ = f |
This Python bug looks related: http://bugs.python.org/msg195244 |
This change effectively hides the error, but I really don't want to do this: diff --git a/spotify/__init__.py b/spotify/__init__.py
index 857bc84..1327d46 100644
--- a/spotify/__init__.py
+++ b/spotify/__init__.py
@@ -56,8 +56,11 @@ def serialized(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
- with _lock:
- return f(*args, **kwargs)
+ try:
+ with _lock:
+ return f(*args, **kwargs)
+ except:
+ pass
if not hasattr(wrapper, '__wrapped__'):
# Workaround for Python < 3.2
wrapper.__wrapped__ = f |
I can't reproduce this bug with cffi 1.0 development snapshot. cffi 1.0 final will hopefully be released early next week. pyspotify will require cffi 1.0 as soon as it is available. |
When using pyspotify 2 (newest develop at current time) and python 3, I get this error when my script exits:
It happens consistently, every time. The only code needed to make it happen is this:
I'm running Python 3.4.0. When running Python 2.7.6, I don't get this error.
The text was updated successfully, but these errors were encountered: