Sep-23-2018, 06:41 AM
I wrote a short test program to learn how to make threads. Right now there is only 1 thread. Going to increase that once I get it working.
It is throwing and error and I am not sure what I am doing wrong. Please advise. Thanks.
It is throwing and error and I am not sure what I am doing wrong. Please advise. Thanks.
#Threading Test2 v1.0 from random import randint import time, threading def main(): times = [] for x in range(10): targetVar = 0 start = time.time() t = threading.Thread(target = varUpdater, name = 'Thread1', args = (targetVar)) t.start() end = time.time() times.append(end - start) average = (sum(times)/ len(times)) print (average) def varUpdater(targetVar): var = randint(0, 100) time.sleep(0.01) if var > targetVar: return var else: return targetVar if __name__ == '__main__': main()
Error:Exception in thread Thread1:
Traceback (most recent call last):
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: varUpdater() argument after * must be an iterable, not int
Exception in thread Thread1:
Traceback (most recent call last):
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: varUpdater() argument after * must be an iterable, not int
Exception in thread Thread1:
Traceback (most recent call last):
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: varUpdater() argument after * must be an iterable, not int
Exception in thread Thread1:
Traceback (most recent call last):
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: varUpdater() argument after * must be an iterable, not int
Exception in thread Thread1:
Traceback (most recent call last):
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: varUpdater() argument after * must be an iterable, not int
Exception in thread Thread1:
Traceback (most recent call last):
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: varUpdater() argument after * must be an iterable, not int
0.0006911277770996094Exception in thread Thread1:
Traceback (most recent call last):
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: varUpdater() argument after * must be an iterable, not int
Exception in thread Thread1:
Traceback (most recent call last):
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: varUpdater() argument after * must be an iterable, not int
Exception in thread Thread1:
Traceback (most recent call last):
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: varUpdater() argument after * must be an iterable, not int
Exception in thread Thread1:
Traceback (most recent call last):
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\jarrod0987\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: varUpdater() argument after * must be an iterable, not int