I have this server
import zerorpc
import time
class MyServer(object):
def fast(self):
return 'FAST'
def slow(self):
for i in range(5):
time.sleep(1)
zerorpc.gevent.sleep(0)
return 'SLOW'
server = zerorpc.Server(MyServer(), heartbeat=None)
try:
zerorpc.gevent.spawn(server.run)
while True:
zerorpc.gevent.sleep(1)
except KeyboardInterrupt:
print("KeyboardInterrupt Received!")
server.close()
Now if I call slow first then fast, then fast is blocked for whole run time of slow. See this
[1] 31651
'FAST'
'SLOW'
real 0m5.072s
user 0m0.084s
sys 0m0.044s
Steps
1. slow is executed in the background
2. fast is executed wrapped with time
3. Both connect at the same time
4. fast is BLOCKED
5. fast is done
6. fast prints is result
7. slow prints its result
We can see fast executed for 5 seconds. But in slow function zerorpc.gevent.sleep(0) was executed every 1 seconds.
1. shouldn't fast return just after 1 second?
2. How can I make sure fast is not blocking while slow is being executed?