Exception KeyError in module 'threading' #362

Open
fcops opened this Issue Aug 14, 2012 · 6 comments

4 participants

@fcops

The main pgm:

#! /usr/bin/env python

-- coding: latin-1 --

import gevent, gzip
from gevent import monkey; monkey.patch_all()

from bottle import route, run, debug, template, request, error, response, redirect, static_file
from urlparse import parse_qs

...

if name == 'main':
basedatos = sys.argv[-1]
elhost = '192.168.43.129'
if os.getcwd()=='/var/www/lims':
p=8000
run(server='gevent', port=p, host=elhost)
else:
p=8002
debug(True)

run(port=p, host=elhost, reloader=True)

I am on Ubuntu 12.04
Bottle versions 0.11.dev and 0.10.11

When I stop the program (in both folders):

^CException KeyError: KeyError(33551632,) in module 'threading' from '/usr/lib/python2.7/threading.pyc' ignored

When I save a correction:

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 2743, in run
thread.interrupt_main()
KeyboardInterrupt

It doesn't seem to do any harm, but I think you should know.

@defnull
Bottle Micro Web Framework member

I saw that once, too but could not find the cause. Still not sure where the bug is: threading, gevent or bottle?

@fcops

I would say gevent.
if I don't monkey patch I can't use server='gevent' (at least the way I have everything):

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 2745, in run
time.sleep(self.interval)
File "/usr/lib/python2.7/dist-packages/gevent/hub.py", line 79, in sleep
switch_result = get_hub().switch()
File "/usr/lib/python2.7/dist-packages/gevent/hub.py", line 135, in get_hub
raise NotImplementedError('gevent is only usable from a single thread')
NotImplementedError: gevent is only usable from a single thread

@Kerrigan29a

This bug is still active.

I'm also on Unbuntu 12.04 with python2.7, gevents and bottle0.12

Executing the gevent example of the documentation:

from gevent import monkey; monkey.patch_all()
from time import sleep
from bottle import route, run, default_app
@route('/stream')
def stream():
    yield 'START'
    sleep(3)
    yield 'MIDDLE'
    sleep(5)
    yield 'END'
app = default_app()

with the following command:

./bottle.py --debug --reload --server gevent --bind 0.0.0.0:8080 main:app

I get the same error:

Bottle v0.12-dev server starting up (using GeventServer())...
Listening on http://0.0.0.0:8080/
Hit Ctrl-C to quit.

[...]

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "../bottle.py", line 2769, in run
    thread.interrupt_main()
KeyboardInterrupt
@iurisilvio
Bottle Micro Web Framework member

I tried a lot to reproduce it, but it works fine here on Ubuntu 11.10 and python 2.7.2.

gevent==0.13.0 (python-gevent on ubuntu)
bottle==0.10.11

I used @Kerrigan29a example and ran apache bench:

$ ab -c 1000 -n 10000 http://localhost:8080/stream
@Kerrigan29a

Sorry I forgot to remark that this error is triggered when the python file is modified while running the server.

@iurisilvio
Bottle Micro Web Framework member

Ok, now I at least reproduced it.

Bottle reloader does not work fine with all servers. I don't know if it is easy to make it work with gevent.

@enigmagroup enigmagroup added a commit to enigmagroup/enigmabox-openwrt that referenced this issue Dec 10, 2014
@enigmagroup enigmagroup Bottle reloader does not work fine with all servers 7114f9a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment