【问题标题】:TypeError: '>' not supported between instances of 'float' and 'Synchronized'TypeError:“浮动”和“同步”的实例之间不支持“>”
【发布时间】:2020-11-09 08:51:15
【问题描述】:
if math.fabs(time.time()-start_time) > time_interval :

TypeError: '>' 在 'float' 和 'Synchronized' 的实例之间不支持

代码:

if __name__ == "__main__":
    start_time =  multiprocessing.Value( 'd', 0.0)
    time_t = multiprocessing.Value('d', 0.005)
    producer(all_client, q[0], time_t, start_time, t)

...

def producer(sequence, output_q, time_interval, start_time, t):
    start_time = t = time.time()
    for item in sequence:
        time.sleep(random.expovariate(glamda[0]))
        item.time_arrived = item.V_entered[0]= time.time()
        output_q.put(item)
        
        if math.fabs(time.time()-start_time) > time_interval :
            print("producer time out ", time_t)
            break 

【问题讨论】:

    标签: python-3.x synchronized consumer producer multiqueue


    【解决方案1】:

    我不确定你想得到什么。但是您可以通过从 Synchronized 对象中获取值来解决此错误(这不是浮点数,您可以从该对象中提取值)。
    替换:
    if math.fabs(time.time()-start_time) > time_interval
    至:
    if math.fabs(time.time()-start_time) > time_interval.value

    【讨论】:

      猜你喜欢
      • 2020-09-07
      • 2021-11-21
      • 1970-01-01
      • 2017-09-14
      • 2017-09-28
      • 2018-01-10
      • 2018-06-03
      • 2018-09-03
      • 2018-05-22
      相关资源
      最近更新 更多