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

Strange behavior when calling into self. #757

Open
yihuang opened this issue May 18, 2015 · 2 comments
Open

Strange behavior when calling into self. #757

yihuang opened this issue May 18, 2015 · 2 comments

Comments

@yihuang
Copy link

yihuang commented May 18, 2015

Recently i encounter a strange behavior, i'm not sure if it's normal.
The following programs are made only to demonstrate the issue, the real world application is more complex.

from bottle import route, app
import urllib2

@route('/a')
def a():
    return 'a'

@route('/b')
def b():
    urllib2.urlopen('http://localhost:10001/a')
    return 'SUCCESS'

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    make_server('127.0.0.1', 10001, app()).serve_forever()
$ curl http://localhost:10001/b

This request would block indefinitely.
And if i use gevent, it won't block, but it shows some even more strange behavior.

from gevent import monkey
monkey.patch_all()

from bottle import route, app
import urllib2

@route('/a')
def a():
    return 'a'

@route('/b')
def b():
    urllib2.urlopen('http://localhost:10001/a')
    return 'SUCCESS'

if __name__ == '__main__':
    from gevent.pywsgi import WSGIServer
    WSGIServer(('127.0.0.1', 10001), app()).serve_forever()
$ curl http://localhost:10001/b
S

Currently, i sidestep this issue by spawn a thread to execute the http request.

@foxbunny
Copy link

Indeed strange, but I've got to ask: why do you even need to do it?

@defnull
Copy link
Member

defnull commented Jun 5, 2015

wsgiref.simple_server is single-threaded. Calling into itself cannot work. It's actually a nice example for a deadlock :)

The second example is indeed strange.

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

3 participants