python - Thread seems to be blocking the process -




class myclass():     def __init__(self):         ...      def start(self):         colorthread = threading.thread(target = self.colorindicator())         colorthread.start()           while true:             print ('something')             ...             ... 

i have print statement inside colorindicator(). statement getting printed. print statement inside while loop of start() method isn't displayed on screen.

the colorindicator() has infinite loop. gets data internet , updates counter. counter initialized inside __init__ self variable , i'm using variable inside other methods.

i not understand why print inside while not being executed.

colorindicator function:

def colorindicator(self):         print ('something else')         ...         while (true):             ...             print ('here')         time.sleep(25) 

the output following:

something else here here 

i stopped after that. so, colorindicator running completely. i'm calling script import in python interpreter (in terminal). instantiate myclass , call start function.

you're not running colorindicator in thread, because called in main thread, rather passing method (uncalled) thread target. change:

    colorthread = threading.thread(target=self.colorindicator())     #                                                        ^^ agh! call parens! 

to:

    # remove parens pass method, without calling     colorthread = threading.thread(target=self.colorindicator)     #                                                        ^ note: no call parens 

basically, problem before ever construct thread, it's trying run colorindicator completion can use return value target, wrong in multiple ways (the method never returns, , if did, wouldn't return callable suitable use target).





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -