Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

'_lock' is not defined on exit when using python 3 #133

Closed
trygveaa opened this issue May 14, 2014 · 7 comments
Closed

'_lock' is not defined on exit when using python 3 #133

trygveaa opened this issue May 14, 2014 · 7 comments
Labels
Milestone

Comments

@trygveaa
Copy link
Contributor

When using pyspotify 2 (newest develop at current time) and python 3, I get this error when my script exits:

Exception ignored in: <function GcWeakrefs.__init__.<locals>.remove at 0x7f9c06ea4b70>
Traceback (most recent call last):
  File "/home/trygve/dev/pyspotify/venv3/lib/python3.4/site-packages/cffi-0.8.2-py3.4-linux-x86_64.egg/cffi/gc_weakref.py", line 12, in remove
  File "/home/trygve/dev/pyspotify/spotify/__init__.py", line 57, in wrapper
NameError: name '_lock' is not defined

It happens consistently, every time. The only code needed to make it happen is this:

import spotify
session = spotify.Session()

I'm running Python 3.4.0. When running Python 2.7.6, I don't get this error.

@jodal jodal added 2.x labels May 14, 2014
@jodal jodal self-assigned this May 14, 2014
@jodal jodal added this to the v2.0.0b4 milestone May 14, 2014
@ghost
Copy link

ghost commented May 23, 2014

Same here. Python 3.4.1 though.

@jodal
Copy link
Owner

jodal commented Jun 26, 2014

This is probably some issue with the order objects are garbage collected on Python shutdown.

@rcompton
Copy link

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

@jodal jodal modified the milestones: v2.0.0b4, v2.0.0b5 Jan 14, 2015
@jodal
Copy link
Owner

jodal commented Mar 11, 2015

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 NameError: name 'NameError' is not defined exception!

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

@jodal
Copy link
Owner

jodal commented Mar 11, 2015

This Python bug looks related: http://bugs.python.org/msg195244

@jodal
Copy link
Owner

jodal commented Mar 11, 2015

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

@jodal jodal removed their assignment Mar 11, 2015
@jodal jodal removed the 2.x label Mar 25, 2015
@jodal jodal modified the milestones: v2.0.0b5, v2.0.0 Mar 25, 2015
@jodal
Copy link
Owner

jodal commented May 8, 2015

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.

@jodal jodal modified the milestones: v2.0.0b5, v2.0.0 May 8, 2015
@jodal jodal closed this as completed in d99834d May 19, 2015
@jodal jodal removed the 2 - Working label May 19, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants