TypeError:“ function”和“ function”的实例P2至P3之间不支持“ <”

时间:2019-02-25 02:33:38

标签: python python-3.x sorting containers heapq

我正在将经过验证的Python 2.7工作代码迁移到python 3.6.3中,但是要面对TypeError:-

Traceback (most recent call last):
  File "epto.py", line 1020, in <module>
    init()
  File "epto.py", line 85, in init
    CYCLE(node)
  File "epto.py", line 133, in CYCLE
    sim.schedulleExecutionBounded(CYCLE, myself, nodeState[myself][CURRENT_CYCLE])
  File "C:\Users\Acer\sim\sim.py", line 103, in schedulleExecutionBounded
    heapq.heappush(queue,(ts,(f,[node])) )
TypeError: '<' not supported between instances of 'function' and 'function'

在sim.py中,代码的最后一行后面的第103行:-

    heapq.heappush(queue,(ts,(f,[node])) )

def schedulleExecutionBounded(f,node,cycle):
    #return random.randint(NODE_CYCLE-NODE_DRIFT, NODE_CYCLE+NODE_DRIFT)
    ts = random.randint(NODE_CYCLE*cycle-NODE_DRIFT,NODE_CYCLE*cycle+NODE_DRIFT)
    #prevent executing in the past
    if ts <= timestamp:
        ts = timestamp+1
    heapq.heappush(queue,(ts,(f,[node])) )

在epto.py中,最后一行代码后的第133行:-

    # schedule execution
    if nodeState[myself][CURRENT_CYCLE] < nbCycles + TTL * 10:
        # sim.schedulleExecution(CYCLE,myself)
        sim.schedulleExecutionBounded(CYCLE, myself, nodeState[myself][CURRENT_CYCLE])

在epto.py中,最后一行代码后面的第85行:-

    for node in nodeIds:
        cyclon_boot(node, random.sample(list(nodeState), CACHE_SIZE))
        CYCLE(node)

在epto.py中,最后一行代码的第1020行:-

    print ('Configuration done')
    init()

说明:

将事件放入堆中进行排序,然后按照时间戳顺序将其交付给应用程序。 问题似乎是堆正在尝试比较完整的元组(ts,(f,[node])),而不仅仅是第一个元素“ ts”。 也许Python 3中的新版本堆具有某种比较器/键,可以用来指定排序需要由ts而不是(ts,(f,[node]))??来完成。

感谢所有帮助,如果不清楚,将改善问题。谢谢。

0 个答案:

没有答案