Skip to content

Instantly share code, notes, and snippets.

@zhangclb
Created July 23, 2016 13:47
Show Gist options
  • Save zhangclb/7e173a40ce7dcfef6645c894811593c8 to your computer and use it in GitHub Desktop.
Save zhangclb/7e173a40ce7dcfef6645c894811593c8 to your computer and use it in GitHub Desktop.
uliweb gevent race condition
~$ prun "t1: curl -s localhost:8000/t1?v=1" "t2: curl -s localhost:8000/t2?v=2"
1 t1: curl -s localhost:8000/t1?v=1
2 t2: curl -s localhost:8000/t2?v=2
t2: t2: v=2, v_after_sleep=1
t2: --- end ---
t1: t1: v=1, v_after_sleep=1
t1: --- end ---
#coding=utf-8
from uliweb import expose, functions
import gevent
@expose('/t1')
def t1():
v = request.values.get("v")
gevent.sleep(5)
v_after_sleep = request.values.get("v")
return 't1: v=%s, v_after_sleep=%s\n'%(v,v_after_sleep)
@expose('/t2')
def t2():
v = request.values.get("v")
gevent.sleep(1)
v_after_sleep = request.values.get("v")
return 't2: v=%s, v_after_sleep=%s\n'%(v,v_after_sleep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment