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

WARNING: gevent: Unable to dereference handle; not stopping watcher. Native resources may leak. #1564

Closed
SteffRainville opened this issue Apr 14, 2020 · 5 comments
Labels
Type: Question

Comments

@SteffRainville
Copy link

SteffRainville commented Apr 14, 2020

  • gevent version: 1.5.0 downloaded with pipenv
  • Python version: 3.8.1 downloaded from python.org"
  • Operating System: Windows 10 Pro build 18363 on Ryzen 9 3900X

Description:

trying to run a very simple background job with Greenlet.spawn and keep getting this warning whenever I do a simple http query in Bottle 0.12.18

WARNING: gevent: Unable to dereference handle; not stopping watcher. Native resources may leak. This is most likely a bug in gevent.

Below minimal program to reproduce bug at will

just localhost:8080/hello

What I've run:

from gevent import monkey; monkey.patch_all()
from gevent import Greenlet
import random
import time
import bottle

from bottle import Bottle, run
app = Bottle()

def get_random():
    while True:
        a = random.randrange(1,6)
        print(a)
        time.sleep(5)

Greenlet.spawn(get_random)

@app.route('/hello')
def hello():
    return "Hello World!"

run(app, host='localhost', port=8080)
@jamadden
Copy link
Member

jamadden commented Apr 14, 2020

I am unable to reproduce that on a POSIX system using libuv. In fact, I can't find that the method in question is ever even called: bottle never closes its socket so the listener is never stopped.

Can you modify AbstractCallbacks.python_stop() in gevent/_ffi/loop.py to print the current traceback when it emits that warning?

@jamadden jamadden added the Type: Question label Apr 14, 2020
@SteffRainville
Copy link
Author

SteffRainville commented Apr 14, 2020

You may have to F5 (refresh ) 4 to 5 times to have the error in Chrome but happens all the time in Edge.

I've added traceback.print_exc(file=sys.stdout) in about 20 places after all except statement but can not manage to print the stack when the Warning is displayed.

@jamadden
Copy link
Member

jamadden commented Apr 14, 2020

I've added traceback.print_exc(file=sys.stdout) in about 20 places after all except statement but can not manage to print the stack when the Warning is displayed.

There's no active exception at that time, so print_exc won't do anything. You just want print_stack.

@SteffRainville
Copy link
Author

SteffRainville commented Apr 14, 2020

I also just confirmed that I can not reproduce on mac.

WARNING: gevent: Unable to dereference handle; not stopping watcher. Native resources may leak. This is most likely a bug in gevent.

  File "C:\Users\steph\.virtualenvs\testbottle-5QKBI09C\lib\site-packages\gevent\hub.py", line 618, in run
    loop.run()
  File "C:\Users\steph\.virtualenvs\testbottle-5QKBI09C\lib\site-packages\gevent\libuv\loop.py", line 511, in run
    ran_status = libuv.uv_run(self._ptr, run_mode)
  File "C:\Users\steph\.virtualenvs\testbottle-5QKBI09C\lib\site-packages\gevent\_ffi\loop.py", line 302, in python_prepare_callback
    loop._run_callbacks()
  File "C:\Users\steph\.virtualenvs\testbottle-5QKBI09C\lib\site-packages\gevent\libuv\loop.py", line 208, in _run_callbacks
    self._prepare_ran_callbacks = self.__run_queued_callbacks()
  File "C:\Users\steph\.virtualenvs\testbottle-5QKBI09C\lib\site-packages\gevent\libuv\loop.py", line 467, in __run_queued_callbacks
    _callbacks.python_stop(None)
  File "C:\Users\steph\.virtualenvs\testbottle-5QKBI09C\lib\site-packages\gevent\_ffi\loop.py", line 259, in python_stop
    traceback.print_stack()

@kkzimieras
Copy link

kkzimieras commented Apr 15, 2020

I can also confirm I was able to reproduce the issue with gevent version: 1.5.0.
No such warnings if gevent==1.4.0 is installed

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

No branches or pull requests

3 participants