~ubuntu-branches/ubuntu/saucy/uwsgi/saucy

« back to all changes in this revision

Viewing changes to tests/testgevent.py

  • Committer: Package Import Robot
  • Author(s): Janos Guljas
  • Date: 2012-04-30 17:35:22 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120430173522-qucwu1au3s9bflhb
Tags: 1.2+dfsg-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# uwsgi -s :3031 -M -p 4 --plugin gevent --loop gevent --async 1000 --enable-threads -w tests.testgevent
 
2
from threading import Thread
 
3
import gevent
 
4
import uwsgi
 
5
import time
 
6
 
 
7
def microtask(wid):
 
8
    print "i am a gevent task"
 
9
    gevent.sleep(10)
 
10
    print "10 seconds elapsed in worker id %d" % wid
 
11
 
 
12
def athread():
 
13
    while True:
 
14
        time.sleep(1)
 
15
        print "i am the thread 1"
 
16
 
 
17
def athread2():
 
18
    while True:
 
19
        time.sleep(1)
 
20
        print "i am the thread 2"
 
21
 
 
22
t1 = Thread(target=athread)
 
23
t1.daemon = True
 
24
t1.start()
 
25
 
 
26
t2 = Thread(target=athread2)
 
27
t2.daemon = True
 
28
t2.start()
 
29
 
 
30
def application(environ, start_response):
 
31
 
 
32
    gevent.sleep()
 
33
    start_response('200 OK', [('Content-Type','text/html')])
 
34
    yield "sleeping for 3 seconds...<br/>"
 
35
    gevent.sleep(3)
 
36
    yield "done<br/>"
 
37
    gevent.spawn(microtask, uwsgi.worker_id())
 
38
    yield "microtask started<br/>"
 
39