<timer(thread-1,started =“” 11268)=“”> Python,threading.Timer问题

时间:2019-04-12 12:04:27

标签: python timer python-multithreading

在我看来,我缺少关于threading.Timer如何工作的一些关键知识。到目前为止,我一直在尝试找到一些代码来帮助我理解Timer等的args和kwargs,但我一直很不幸。

我正在尝试通过创建一些与Wow Casting机制类似的代码来学习。如您所见,它是非常原始的,但是现在我多次遇到这个错误。有人可以详细说明我对threading.Timer的理解是什么问题,以便将来我可以毫不犹豫地使用它吗? 预先谢谢你。

from threading import Timer

def scope(x):
    if x<0:
        print("Has to be between 1 and 0")
    elif x>1:
        print("Has to be between 1 and 0")
    else:
        return x

def damage(spp,res):
    scope(res)
    c = spp - spp*res
    return c

def fire_projectile():
    print("Projectile fired!")
def casting_time(n_time,haste):
    #Every haste unit deducts the casting time by 0.001 seconds.
    general_time = n_time - haste/1000.00
    print(general_time)
    c = Timer(general_time, lambda: fire_projectile())
    c.start()
    return c
    #The timer is here to count down the time needed in order for projectile to get launched.#
spells = {'Fireball': (250, 2), 'Pyrobalst' : (400, 3), 'Flamestrike': (190, 1.5)}
#First value is the natural damage of the spell. Second value is the casting time w/o haste.
classes = {'Death Knight': (0.6, 500), 'Mage': (0.2, 1200), "Priest": (0.4, 800)}
#First value is resistance to fire damage. Second value is haste.


print(damage(spells['Fireball'][0],classes['Death Knight'][0]))
print(casting_time(spells['Fireball'][1], classes['Mage'][1]))

在我写了最后两行之后,第一行似乎运行良好,但是第二行有一些问题。

代替: 100.0 0.8 发射子弹!

以退出代码0结束的过程

我得到了: 100.0 0.8 计时器(线程1,已启动11268) 发射子弹!

以退出代码0结束的过程

0 个答案:

没有答案