Exemple #1
0
def application(env, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

    mytemplate = Template("<h1>I am Mako at ${thetime}</h1>")
    uwsgi.green_schedule()

    yield mytemplate.render(thetime=time.time())

    for i in range(1, 100):
        mytemplate = Template("Iteration ${thei} at ${thetime}<br/>")
        uwsgi.green_schedule()
        yield mytemplate.render(thei=i, thetime=time.time())
Exemple #2
0
def application(env, start_response):
	counter = 0
	start_response( '200 OK', [ ('Content-Type','text/html') ])
	start_time = time.time()
	for i in range(1,100000):
		uwsgi.green_schedule()
		# print every 100
		if i % 100 == 0:
			yield "<h1>%d</h1>\n" % i
		counter = counter + i

	yield "<h1>%d cycles after %d</h1>\n" % (counter, time.time() - start_time)
Exemple #3
0
def send_request(env, client):

    client.setblocking(1)

    client.send(b"GET /intl/it_it/images/logo.gif HTTP/1.0\r\n")
    client.send(b"Host: www.google.it\r\n\r\n")

    uwsgi.green_schedule()

    while 1:
        uwsgi.green_wait_fdread(client.fileno(), 10)
        buf = client.recv(4096)
        if len(buf) == 0:
            break
        else:
            yield buf
Exemple #4
0
def send_request(env, client):

    client.setblocking(1)

    client.send(b"GET /intl/it_it/images/logo.gif HTTP/1.0\r\n")
    client.send(b"Host: www.google.it\r\n\r\n")

    uwsgi.green_schedule()

    while 1:
        uwsgi.green_wait_fdread(client.fileno(), 10)
        buf = client.recv(4096)
        if len(buf) == 0:
            break
        else:
            yield buf
Exemple #5
0
def application(env, start_response):

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setblocking(0)

    c = s.connect_ex(('74.125.77.104', 80))
    if c == errno.EINPROGRESS:
        uwsgi.green_wait_fdwrite(s.fileno(), 10)
        for r in send_request(env, s):
            yield r
    elif c == errno.EISCONN:
        for r in send_request(env, s):
            yield r
    else:
        uwsgi.green_schedule()
        start_response('500 Internal Server Error', [('Content-Type', 'text/html')])
        yield "Internal Server Error"

    s.close()
Exemple #6
0
def application(env, start_response):

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setblocking(0)

    c = s.connect_ex(('74.125.77.104', 80))
    if c == errno.EINPROGRESS:
        uwsgi.green_wait_fdwrite(s.fileno(), 10)
        for r in send_request(env, s):
            yield r
    elif c == errno.EISCONN:
        for r in send_request(env, s):
            yield r
    else:
        uwsgi.green_schedule()
        start_response('500 Internal Server Error',
                       [('Content-Type', 'text/html')])
        yield "Internal Server Error"

    s.close()