Hi. I am trying to make a script that will print out numbers in rapid succession after working a little with them. The script needs to write them in the console one after another (next line). The code works just fine when I do not utilize multi threading, but when I do, I still get the right numbers, but from time to time there is a white space at the beginning of the line. That is a major issue, because then the program fails to work (when it is being tested.
Is there a way to get several threads to work together, printing to the console very close to each other without this bug?
here is some of the code:
class myThread(threading.Thread):
def __init__ ( self, value, coins ):
self.val = value
self.coi = coins
threading.Thread.__init__ ( self )
def run ( self ):
someMethod(self.coi, self.val)#this prints a value after working a little.
#SOME CODE
#SOME CODE
#SOME CODE
#SOME CODE
#SOME CODE
for line in stdin:
myThread(int(line),coins).start()
I get output that is a variation of:
3
8
4
with or without a single space in front of some (or all) of the numbers.
Thanks for the help:)