我有多个在一个公共套接字上发送的小绿灯。是否保证通过发送的每个包socket.sendall都被很好地分开,或者我是否必须在每次调用sendall.
所以我想防止以下情况:
- g1发送
ABCD - g2发送
1234 - 接收到的数据被混淆了,例如
AB1234CD - 预期是
ABCD1234或1234ABCD
更新
查看源代码后,我认为这种情况不会发生。但我必须使用锁,因为 g1 或 g2 可能会在sendall. 有人可以证实这一点吗?
我用高延迟/低带宽接口做了一些测试,得到了预期的错误。
这导致(如预期的那样)以下错误:
AssertionError: This event is already used by another greenlet: (<Greenlet
at 0x7f3e758722d0: <bound method socket.sendall of <socket at 0x7f3e7587719
0 fileno=8 sock=127.0.0.1:1234 peer=127.0.0.1:51042>>('11111111111111111111
11111111111111111111111111111)>, timeout('timed out',))
这是固定的测试脚本,gevent.coros.RLock它不会产生此错误:https ://gist.github.com/4249827/7f02f805331eda4091ae0b39dfea4b102cdba2fa