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

Django runserver throws AttributeError on closing #158

Open
slimadvies opened this issue Dec 18, 2024 · 18 comments · Fixed by #159 · May be fixed by #166
Open

Django runserver throws AttributeError on closing #158

slimadvies opened this issue Dec 18, 2024 · 18 comments · Fixed by #159 · May be fixed by #166
Assignees
Labels
bug Something isn't working

Comments

@slimadvies
Copy link

When closing django-admin runserver, Valkey client consistently throws an attribute exception.

This is the same issue as redis/redis-py#3014

My setup:
Macos 15.2
Python 3.13.1
Django 4.2.17
Valkey-py 6.0.2

$ django-admin runserver

December 18, 2024 - 14:31:26
Django version 4.2.17, using settings 'milieubarometer_conf.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

^CException ignored in: <function Valkey.del at 0x106c76a20>
Traceback (most recent call last):
File ".../lib/python3.13/site-packages/valkey/client.py", line 521, in del
File ".../site-packages/valkey/client.py", line 536, in close
File ".../lib/python3.13/site-packages/valkey/connection.py", line 1179, in disconnect
File ".../lib/python3.13/site-packages/valkey/connection.py", line 1083, in _checkpid
AttributeError: 'NoneType' object has no attribute 'getpid'

@amirreza8002
Copy link
Contributor

hi
can you show the code that is using valkey?

@spyinx
Copy link
Contributor

spyinx commented Dec 18, 2024

@amirreza8002 it's easy to reproduce:

>>> from valkey.client import Valkey
>>> r = Valkey(host="127.0.0.1", port=6379)
>>> exit()
Exception ignored in: <function Valkey.__del__ at 0x7efcc1b28900>
Traceback (most recent call last):
  File "/root/valkey-learning/valkey-py-6.0.2/valkey/client.py", line 521, in __del__
  File "/root/valkey-learning/valkey-py-6.0.2/valkey/client.py", line 536, in close
  File "/root/valkey-learning/valkey-py-6.0.2/valkey/connection.py", line 1180, in disconnect
  File "/root/valkey-learning/valkey-py-6.0.2/valkey/connection.py", line 1084, in _checkpid
TypeError: 'NoneType' object is not callable
(env-3.13) [root@spyinx valkey-py-6.0.2]# 

just use valkey-py in a subprocess, like python shell et.

@amirreza8002
Copy link
Contributor

amirreza8002 commented Dec 18, 2024

hi
perhaps, but I'm more interested in the django part, how is valkey used in django in this context?
i use valkey with django and it exits cleanly

since i maintain django-valkey, i would want to know if there's a problem

or perhaps if i there's a fix i know about

@mkmkme
Copy link
Collaborator

mkmkme commented Dec 18, 2024

@spyinx I couldn't reproduce this on my machine (Linux). What setup do you have?

@mkmkme
Copy link
Collaborator

mkmkme commented Dec 18, 2024

@spyinx also it looks like your error is different from the one @slimadvies has

@spyinx
Copy link
Contributor

spyinx commented Dec 18, 2024

@spyinx also it looks like your error is different from the one @slimadvies has

@mkmkme same error in one place, i just use python3.13 to learn valkey-py code, when i exit python shell, it alway occurs this exception.

(env-3.13) [root@spyinx valkey-py-6.0.2]# python --version
Python 3.13.0
(env-3.13) [root@spyinx valkey-py-6.0.2]# uname -a
Linux spyinx 5.10.134-15.al8.x86_64 #1 SMP Thu Jul 20 00:44:04 CST 2023 x86_64 x86_64 x86_64 GNU/Linux
(env-3.13) [root@spyinx valkey-py-6.0.2]# cat /etc/redhat-release 
Alibaba Cloud Linux release 3 (Soaring Falcon) 
(env-3.13) [root@spyinx valkey-py-6.0.2]# python3
Python 3.13.0 (main, Nov 22 2024, 11:00:19) [GCC 10.2.1 20200825 (Alibaba 10.2.1-3.8 2.32)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from valkey.client import Valkey
>>> r = Valkey(host="127.0.0.1", port=6379)
>>> exit()
Exception ignored in: <function Valkey.__del__ at 0x7fae26598c20>
Traceback (most recent call last):
  File "/root/valkey-learning/valkey-py-6.0.2/valkey/client.py", line 521, in __del__
  File "/root/valkey-learning/valkey-py-6.0.2/valkey/client.py", line 536, in close
  File "/root/valkey-learning/valkey-py-6.0.2/valkey/connection.py", line 1179, in disconnect
  File "/root/valkey-learning/valkey-py-6.0.2/valkey/connection.py", line 1083, in _checkpid
TypeError: 'NoneType' object is not callable
(env-3.13) [root@spyinx valkey-py-6.0.2]# 

@mkmkme
Copy link
Collaborator

mkmkme commented Dec 18, 2024

@spyinx ah true, I stand corrected. I also was able to reproduce it with 6.0.2 from PyPI. But couldn't reproduce with current main branch.

Could you try using main branch and tell if there's any difference? In the meantime, I'll dig into this.

Thanks for the info!

@mkmkme
Copy link
Collaborator

mkmkme commented Dec 18, 2024

Interestingly enough, it doesn't occur in ipython (which I mainly use), but does appear in regular python repl

@amirreza8002
Copy link
Contributor

hi
i can reproduce it with main

>>> from valkey import Valkey
>>> v = Valkey()
>>> exit()
Exception ignored in: <function Valkey.__del__ at 0x770a28e55300>
Traceback (most recent call last):
  File "/home/amirreza/projects/valkey-py/valkey/client.py", line 521, in __del__
  File "/home/amirreza/projects/valkey-py/valkey/client.py", line 536, in close
  File "/home/amirreza/projects/valkey-py/valkey/connection.py", line 1179, in disconnect
  File "/home/amirreza/projects/valkey-py/valkey/connection.py", line 1083, in _checkpid
TypeError: 'NoneType' object is not callable

but i'd like to emphsis that i've never seen the django one

@amirreza8002
Copy link
Contributor

Interestingly enough, it doesn't occur in ipython (which I mainly use), but does appear in regular python repl

bpython also exits cleanly, i just saw

@amirreza8002
Copy link
Contributor

python 3.12.8 also doesn't error, seems like a 3.13 problem

@mkmkme mkmkme added the bug Something isn't working label Dec 18, 2024
@mkmkme
Copy link
Collaborator

mkmkme commented Dec 18, 2024

Thanks @amirreza8002 ! Can confirm it doesn't fail on Python 3.12.

I will start investigating now and hopefully will come up with a solution soon.

@spyinx
Copy link
Contributor

spyinx commented Dec 18, 2024

yes, only python3.13 has the same problem, i used both versions in python3.12, it's ok

[root@spyinx valkey-py-6.0.2]# python3
Python 3.12.4 (main, Nov 13 2024, 10:46:13) [GCC 10.2.1 20200825 (Alibaba 10.2.1-3.8 2.32)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from valkey import __version__
>>> __version__
'6.0.2'
>>> from valkey.client import Valkey
>>> r = Valkey(host="127.0.0.1", port=6379)
>>> exit()
[root@spyinx valkey-py-6.0.2]#
[root@spyinx valkey-py]# python3
Python 3.12.4 (main, Nov 13 2024, 10:46:13) [GCC 10.2.1 20200825 (Alibaba 10.2.1-3.8 2.32)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from valkey import __version__
>>> __version__
'6.1.0b1'
>>> from valkey.client import Valkey
>>> r = Valkey(host="127.0.0.1", port=6379)
>>> exit()
[root@spyinx valkey-py]#
(env-3.13) [root@spyinx valkey-py]# pyenv activate env-3.13
(env-3.13) [root@spyinx valkey-py]# python3
Python 3.13.0 (main, Nov 22 2024, 11:00:19) [GCC 10.2.1 20200825 (Alibaba 10.2.1-3.8 2.32)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from valkey import __version__
>>> __version__
'6.1.0b1'
>>> from valkey.client import Valkey
>>> r = Valkey(host="127.0.0.1", port=6379)
>>> exit()
Exception ignored in: <function Valkey.__del__ at 0x7f0e014ac2c0>
Traceback (most recent call last):
  File "/root/valkey-learning/fix2/valkey-py/valkey/client.py", line 521, in __del__
  File "/root/valkey-learning/fix2/valkey-py/valkey/client.py", line 536, in close
  File "/root/valkey-learning/fix2/valkey-py/valkey/connection.py", line 1179, in disconnect
  File "/root/valkey-learning/fix2/valkey-py/valkey/connection.py", line 1083, in _checkpid
TypeError: 'NoneType' object is not callable
(env-3.13) [root@spyinx valkey-py]#

@mkmkme mkmkme self-assigned this Dec 18, 2024
@mkmkme
Copy link
Collaborator

mkmkme commented Dec 18, 2024

Just a small note for everyone in this thread: valkey-py 6.0.2 doesn't yet officially support Python 3.13.

We have 6.1.0b1 with Python 3.13 support, but clearly it is affected by the same issue.

Thank you everyone for drawing attention to this, it should be fixed in stable 6.1.0

@amirreza8002
Copy link
Contributor

amirreza8002 commented Dec 18, 2024

for what it's worth, about the issue itself, i just tested django + valkey in python3.13 and did not have this issue
i checked both runserver and django shell

as refrence, my setup (django-valkey) uses connection pools to connect to valkey, which is then handled by django itself

@mkmkme
Copy link
Collaborator

mkmkme commented Dec 18, 2024

Yeah I'm not sure what setup @slimadvies is using, but my guess is that when we fix it for just Python subprocess, it'll be fixed for them as well.

@slimadvies
Copy link
Author

Thanks. This should fix it. Nice investigating. 👍

@mkmkme
Copy link
Collaborator

mkmkme commented Dec 20, 2024

Got the same issue while testing the sentinel code, will have to fix it as well.

@mkmkme mkmkme reopened this Dec 20, 2024
mkmkme added a commit to mkmkme/valkey-py that referenced this issue Dec 23, 2024
Previous fix only handled the connections from `Valkey` class, which
left classes like `Sentinel` broken because those are handled in
`AbstractConnection`.
Also after merging previous fix I was pointed to the place in Python
standard library where the similar issue was handled by having
`from os import getpid` instead of having a local object assigned to
`os.getpid`.

Fixes valkey-io#158

Signed-off-by: Mikhail Koviazin <[email protected]>
@mkmkme mkmkme linked a pull request Dec 23, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants