Python eventlet AssertionError:尝试重新发送()已经触发的事件

时间:2018-10-26 10:05:36

标签: events python-3.6 sleep eventlet

我使用以下代码进行测试,但提示“ AssertionError:尝试重新发送()已经触发的事件”。错误,这应该是多次调用的事件,但是我没有发现她多次调用,我不知道这是什么原因, 但是没有sleep(7),没有错误将被报告。 。请向我解释。

import eventlet
from eventlet import Event
from eventlet import sleep

values = [1, 2, 3, 4, 5, 6]

def func(value):
    sleep(1)
    return value

def main():
    results = []
    pool = eventlet.GreenPool()

    for value in values:
        event = Event()
        gt = pool.spawn(func, value)
        gt.link(lambda res: event.send(res.wait()))
        results.append(event)

    sleep(7)
    for result in results:
        if result.ready():
            print('result: %s'%result.wait())
        else:
            print('waiting')


if __name__ == '__main__':
    main()

下面的错误消息

/home/greene/Github/DemoLib/venv36/bin/python /home/greene/Github/DemoLib/scrapyddemo/api.py
Traceback (most recent call last):
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/hubs/hub.py", line 460, in fire_timers
    timer()
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/hubs/timer.py", line 59, in __call__
    cb(*args, **kw)
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/greenthread.py", line 226, in main
    self._resolve_links()
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/greenthread.py", line 237, in _resolve_links
    f(self, *ca, **ckw)
  File "/home/greene/Github/DemoLib/scrapyddemo/api.py", line 46, in <lambda>
    gt.link(lambda res: event.send(res.wait()))
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/event.py", line 162, in send
    assert self._result is NOT_USED, 'Trying to re-send() an already-triggered event.'
AssertionError: Trying to re-send() an already-triggered event.
Traceback (most recent call last):
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/hubs/hub.py", line 460, in fire_timers
    timer()
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/hubs/timer.py", line 59, in __call__
    cb(*args, **kw)
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/greenthread.py", line 226, in main
    self._resolve_links()
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/greenthread.py", line 237, in _resolve_links
    f(self, *ca, **ckw)
  File "/home/greene/Github/DemoLib/scrapyddemo/api.py", line 46, in <lambda>
    gt.link(lambda res: event.send(res.wait()))
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/event.py", line 162, in send
    assert self._result is NOT_USED, 'Trying to re-send() an already-triggered event.'
AssertionError: Trying to re-send() an already-triggered event.
Traceback (most recent call last):
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/hubs/hub.py", line 460, in fire_timers
    timer()
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/hubs/timer.py", line 59, in __call__
    cb(*args, **kw)
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/greenthread.py", line 226, in main
    self._resolve_links()
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/greenthread.py", line 237, in _resolve_links
    f(self, *ca, **ckw)
  File "/home/greene/Github/DemoLib/scrapyddemo/api.py", line 46, in <lambda>
    gt.link(lambda res: event.send(res.wait()))
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/event.py", line 162, in send
    assert self._result is NOT_USED, 'Trying to re-send() an already-triggered event.'
AssertionError: Trying to re-send() an already-triggered event.
Traceback (most recent call last):
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/hubs/hub.py", line 460, in fire_timers
    timer()
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/hubs/timer.py", line 59, in __call__
    cb(*args, **kw)
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/greenthread.py", line 226, in main
    self._resolve_links()
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/greenthread.py", line 237, in _resolve_links
    f(self, *ca, **ckw)
  File "/home/greene/Github/DemoLib/scrapyddemo/api.py", line 46, in <lambda>
    gt.link(lambda res: event.send(res.wait()))
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/event.py", line 162, in send
    assert self._result is NOT_USED, 'Trying to re-send() an already-triggered event.'
AssertionError: Trying to re-send() an already-triggered event.
Traceback (most recent call last):
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/hubs/hub.py", line 460, in fire_timers
    timer()
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/hubs/timer.py", line 59, in __call__
    cb(*args, **kw)
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/greenthread.py", line 226, in main
    self._resolve_links()
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/greenthread.py", line 237, in _resolve_links
    f(self, *ca, **ckw)
  File "/home/greene/Github/DemoLib/scrapyddemo/api.py", line 46, in <lambda>
    gt.link(lambda res: event.send(res.wait()))
  File "/home/greene/Github/DemoLib/venv36/lib/python3.6/site-packages/eventlet/event.py", line 162, in send
    assert self._result is NOT_USED, 'Trying to re-send() an already-triggered event.'
AssertionError: Trying to re-send() an already-triggered event.

0 个答案:

没有答案