Skip to content

TypeError: '>=' not supported between instances of 'int' and 'NoneType' when running the gc #184

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

Closed
tardyp opened this issue Sep 22, 2017 · 9 comments

Comments

@tardyp
Copy link

tardyp commented Sep 22, 2017

How to reproduce easily

pip install pytest neo4j-driver

write a file 'test_neo.py' :

from neo4j.v1 import GraphDatabase, basic_auth
import os

url = os.environ["NEO4J_URL"]
auth = os.environ["NEO4J_AUTH"].split(":")
d = GraphDatabase.driver(url, auth=basic_auth(*auth), encrypted=False)
s = d.session()


def test_neo():
    with s.begin_transaction() as tx:
        tx.run("MATCH (n) RETURN n LIMIT 1")
0 % pytest testneo.py
============================================================================================================================ test session starts =============================================================================================================================
platform darwin -- Python 3.6.2, pytest-3.2.2, py-1.4.34, pluggy-0.4.0
rootdir: /Users/az02096/dev/nestor/gitlab-celery, inifile:
plugins: celery-4.1.0
collected 1 item

testneo.py .

========================================================================================================================== 1 passed in 0.13 seconds ==========================================================================================================================
Exception ignored in: <bound method Driver.__del__ of <neo4j.v1.direct.DirectDriver object at 0x1088400f0>>
Traceback (most recent call last):
  File "[..].venv/lib/python3.6/site-packages/neo4j/v1/api.py", line 151, in __del__
  File "[..].venv/lib/python3.6/site-packages/neo4j/v1/api.py", line 193, in close
  File "[..].venv/lib/python3.6/site-packages/neo4j/bolt/connection.py", line 439, in close
  File "[..].venv/lib/python3.6/site-packages/neo4j/bolt/connection.py", line 428, in remove
  File "[..].venv/lib/python3.6/site-packages/neo4j/bolt/connection.py", line 346, in close
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 1305, in info
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 1546, in isEnabledFor
TypeError: '>=' not supported between instances of 'int' and 'NoneType'
Exception ignored in: <bound method Connection.__del__ of <neo4j.bolt.connection.Connection object at 0x1099fb9e8>>
Traceback (most recent call last):
  File "[..].venv/lib/python3.6/site-packages/neo4j/bolt/connection.py", line 190, in __del__
  File "[..].venv/lib/python3.6/site-packages/neo4j/bolt/connection.py", line 346, in close
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 1305, in info
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 1546, in isEnabledFor
TypeError: '>=' not supported between instances of 'int' and 'NoneType'

Looks like similar issue here:
johanlundberg/neo4j-django-tutorial#10

I am not sire exactly, but it looks like somehow the INFO variable is reset to None at some point. I am not sure if this is because of neo4j-driver or because of pytest

@zhenlineo
Copy link
Contributor

zhenlineo commented Oct 10, 2017

With this fix #188 I could successfully run your example with pytest on python 3 without any problem, while on python 2 I still receive some issues to close all resources properly. It seems pytest or python2 is destroying some resources earlier than it should be. While if I run your example as a python script, then I will not get any error now.

So the best practice I would suggest is: mange the resources properly, a.k.a close the driver yourself rather than relying on closing when the object is out of scope.

@zhenlineo
Copy link
Contributor

Hi @tardyp,

I am closing this issue as we've already fixed what we could fix in #188

The key is still to close the resources. It is still suggested to explicitly to close driver/session/tx to avoid any possible connection leaks in your app.

If you still have any problem regarding this card, be free to reopen it.

Cheers,
Zhen

@TvoroG
Copy link

TvoroG commented May 8, 2018

Hi!
I stuck with the same issue:

Exception ignored in: <bound method Connection.__del__ of <neo4j.bolt.connection.Connection object at 0x7f14961e61d0>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/neo4j/bolt/connection.py", line 212, in __del__
  File "/usr/local/lib/python3.6/site-packages/neo4j/bolt/connection.py", line 385, in close
  File "/usr/local/lib/python3.6/logging/__init__.py", line 1305, in info
  File "/usr/local/lib/python3.6/logging/__init__.py", line 1546, in isEnabledFor
TypeError: '>=' not supported between instances of 'int' and 'NoneType'

Every time django server is reloading or tests finished this message appears.
As @zhenlineo sad problem is incorrect resource managing. In my case it is driver managing. I don't know how properly manage driver in server application. At least it's not so clear.

As a workaround I use atexit module:

import atexit
driver = GraphDatabase.driver(...)
atexit.register(lambda: driver.close())

@jeicoo
Copy link

jeicoo commented Jun 18, 2018

Got the same issue as well.
I am using neo4j-driver version 1.5.2
@zhenlineo is your already included in the version above? Thank you

@zhenlineo
Copy link
Contributor

@jeicoo It should be. You shall not get the error on Python3.
Which python version you are using?
Will you still get the problem if you explicitly close the driver?

@jeicoo
Copy link

jeicoo commented Jun 18, 2018

@zhenlineo thank you for the response!
I am using Python 3.6.
Unfortunately, I am not closing the driver explicitly as I don't know where to close it in Pyramid framework. I initialized the driver in the module level with the main function.

@zhenlineo
Copy link
Contributor

@jeicoo The key is still to shut down the driver properly. I found this simple solution to work around the fact that there is no shutdown event in pyramid here (The same as @TvoroG 's suggestion too)

Let us know if this solves your problem.

@jeicoo
Copy link

jeicoo commented Jun 18, 2018

@zhenlineo yes, as you mentioned in the previous comment to shut down the driver properly. I will keep that in mind.

Thank you for the link that you gave! It looks like that will solve my problem. I was hoping to find the solution to this issue but you showed me on how to handle exit event in pyramid as well. Much appreciated!

@TvoroG thank you for sharing your solution!

Will let you guys know once I solved my problem.

@jeicoo
Copy link

jeicoo commented Jun 19, 2018

@zhenlineo the workaround you gave worked for me! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants