when I am trying to kill a greenlet using kill(), a 'block' param is default by True,

Greenlet.kill(self, exception, block, timeout)

the doc says:

If block is True (the default), wait until the greenlet dies or the optional timeout expires. If block is False, the current greenlet is not unscheduled.

How to understand this properly? thx

有帮助吗?

解决方案

Lets say that you have two greenlets A and B.

1) Inside B you call A.kill(block=True). Immediatly after that context switch happens, Python jumps to A and it raises an exception in A. A may handle it or not, it may jump somewhere else, timeout may occure on kill, etc.

2) Inside B you call A.kill(block=False). Context switch does not happen. B continues to run other commands after kill. Kill command is scheduled to fire though, i.e. as soon as Python jumps to A it will raise the exception.

So AFAIK "block" simply means "do the switch now".

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top