Python execute task -


this question has answer here:

i have python class indefinitely blocking task method

class a(object):    def __init__(self):        # start task     def task(self):        while true:            #do work 

i want start execution of task in constructor of a. need run in own thread task blocking. how in python 2.7?

like mentioned in comments, there's module threading seems fit task. example:

import threading  class a(object):    def __init__(self):        threading.thread(target=self.task).start()     def task(self):        print 'hello thread'  = a()  # output: 'hello thread' 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -