Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'_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
bug
Milestone

Comments

@trygveaa
Copy link
Contributor

@trygveaa trygveaa commented May 14, 2014

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
@ghost

This comment has been minimized.

Copy link

@ghost ghost commented May 23, 2014

Same here. Python 3.4.1 though.

@jodal

This comment has been minimized.

Copy link
Owner

@jodal jodal commented Jun 26, 2014

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

@rcompton

This comment has been minimized.

Copy link

@rcompton rcompton commented Dec 21, 2014

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 added the 1 - Ready label Feb 14, 2015
@jodal

This comment has been minimized.

Copy link
Owner

@jodal 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

This comment has been minimized.

Copy link
Owner

@jodal jodal commented Mar 11, 2015

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

@jodal

This comment has been minimized.

Copy link
Owner

@jodal 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

This comment has been minimized.

Copy link
Owner

@jodal 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 added 2 - Working and removed 1 - Ready labels May 8, 2015
@jodal jodal closed this in d99834d May 19, 2015
@jodal jodal removed the 2 - Working label May 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.