python - Threading with Bottle.py Server -


i'm having issue threading can't solve in way i've tried. searched in stackoverflow too, find cases didn't apply me, or explanations didn't understand.

i'm trying build app bottlepy, , 1 of features want requires function run in background. this, i'm trying make run in thread. however, when start thread, runs twice.

i've read in places possible check if function in main script or in module using if __name__ == '__main__':, i'm not able this, since __name__ returning name of module.

below example of i'm doing right now.

the main script:

# main.py myclass import * bottle import *  arg =  myobject = myclass(arg1)  app = bottle() app.run('''bottle args''') 

the class:

# myclass.py import threading import time  class myclass:     def check_list(self, thelist, arg1):         a_list = something()         time.sleep(5)         self.check_list(a_list, arg1)      def __init__(self, arg1):         if __name__ == '__main__':             self.a_list = arg.returnalist()             t = threading.thread(target=self.check_list, args=(a_list, arg1)) 

so intend here have check_list running in thread time, doing , waiting seconds run again. can have list updated, , able read main script.

can explain me i'm doing wrong, why thread running twice, , how can avoid this?

this works fine:

import threading import time  class myclass:     def check_list(self, thelist, arg1):         keep_going=true         while keep_going:             print("check list")             #do stuff             time.sleep(1)      def __init__(self, arg1):         self.a_list = ["1","2"]         t = threading.thread(target=self.check_list, args=(self.a_list, arg1))         t.start()  myobject = myclass("something") 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -