vendredi 2 octobre 2020

How to generate a random number within a threaded function in Python

I want a random number in a threaded function.

          import random
          import threading
          import Queue

          q = Queue.Queue() 
         

          def fun1(a,x):
                print(a.qsize())
                for i in range(x):        
                      print(a.get(()))       
                      mydata = random.uniform(1,2)
                      print(mydata)


          q.put('a') 
          q.put('b') 
          q.put('c')

          t = threading.Thread(target=fun1, args=(q,3))
          t.start()

For the above program, it gives the following error. But I need a random number Exception has occurred: AttributeError 'NoneType' object has no attribute 'uniform'




Aucun commentaire:

Enregistrer un commentaire