Skip to content

Instantly share code, notes, and snippets.

@miku
Last active March 11, 2019 18:10
Show Gist options
  • Select an option

  • Save miku/4465839 to your computer and use it in GitHub Desktop.

Select an option

Save miku/4465839 to your computer and use it in GitHub Desktop.

Revisions

  1. miku revised this gist Jan 6, 2013. 1 changed file with 27 additions and 14 deletions.
    41 changes: 27 additions & 14 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,36 @@
    #!/usr/bin/env python
    #!/usr/bin/env python
    # http://stackoverflow.com/questions/14180179/eventlet-spawn-doesnt-work-as-expected/14180227#14180227

    from flask import Flask
    import eventlet
    from flask import Flask
    import time
    import eventlet

    eventlet.monkey_patch()
    eventlet.monkey_patch()

    app = Flask(__name__)
    app.debug = True
    app = Flask(__name__)
    app.debug = True


    def background():
    print('This happens in the background')
    def background():
    """ do something in the background """
    print('[background] working in the background...')
    time.sleep(2)
    print('[background] done.')
    return 42


    @app.route('/')
    def index():
    eventlet.spawn(background)
    return "Hello World"
    def callback(gt, *args, **kwargs):
    """ this function is called when results are available """
    result = gt.wait()
    print("[cb] %s" % result)

    if __name__ == '__main__':
    app.run()

    @app.route('/')
    def index():
    greenth = eventlet.spawn(background)
    print(greenth)
    greenth.link(callback)
    return "Hello World"

    if __name__ == '__main__':
    app.run()
  2. miku revised this gist Jan 6, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion app.py
    Original file line number Diff line number Diff line change
    @@ -20,4 +20,4 @@ def index():
    return "Hello World"

    if __name__ == '__main__':
    app.run(
    app.run()
  3. miku created this gist Jan 6, 2013.
    23 changes: 23 additions & 0 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/usr/bin/env python
    # http://stackoverflow.com/questions/14180179/eventlet-spawn-doesnt-work-as-expected/14180227#14180227

    from flask import Flask
    import eventlet

    eventlet.monkey_patch()

    app = Flask(__name__)
    app.debug = True


    def background():
    print('This happens in the background')


    @app.route('/')
    def index():
    eventlet.spawn(background)
    return "Hello World"

    if __name__ == '__main__':
    app.run(