我正在使用mininet模拟器。我想每7秒向主机发送一次命令。我正在使用
threading.Timer()
内部为循环。我需要将参数作为变量传递给函数,该变量改变了循环中的每个迭代 像这样
for ip in ips:
t =threading.Timer(7, attacker.cmd ,args= ("sudo python SYN-ACK.py %s 192.168.1.100 %d 80",))%(ip,ips[ip])
然而,这给了我这个错误
t =threading.Timer(7, attacker.cmd ,args= ("sudo python SYN-ACK.py %s 192.168.1.100 %d 80",))%(ip,ips[ip])
TypeError: unsupported operand type(s) for %: '_Timer' and 'tuple'
在尝试上述解决方案后,我得到了这个例外
Exception in thread Thread-31:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 1082, in run
self.function(*self.args, **self.kwargs)
File "build/bdist.linux-x86_64/egg/mininet/node.py", line 355, in cmd
self.sendCmd( *args, **kwargs )
File "build/bdist.linux-x86_64/egg/mininet/node.py", line 272, in
sendCmd
assert self.shell and not self.waiting
AssertionError
我怎样才能解决这个问题?你知道吗
操作%必须在元组中,最好将任务分开,以便更可读:
相关问题 更多 >
编程相关推荐