Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am looking for a solution for _thread in class object


This is an example of

for a class...


# A minimal threading example with an object
import threading
import time

class MyThread(threading.Thread):
    def run(self):                                        # Default called function with mythread.start()
        print("{} started!".format(self.getName()))        # "Thread-x started!"
        time.sleep(1)                                      # Pretend to work for a second
        print("{} finished!".format(self.getName()))      # "Thread-x finished!"

def main():
    for x in range(4):                                    # Four times...
        mythread = MyThread(name = "Thread-{}".format(x))  # ...Instantiate a thread and pass a unique ID to it
        mythread.start()                                  # ...Start the thread, run method will be invoked
        time.sleep(.9)                                    # ...Wait 0.9 seconds before starting another

if __name__ == '__main__':

Not work With Lobo Micropython, I am looking for a solution for _thread..

import _thread
import time


class MyThread(_thread.Thread):  ? :|


I found this module in internet:


import _thread

class Thread:

    def __init__(self, group=None, target=None, name=None, args=(), kwargs=None): = target
        self.args = args
        self.kwargs = {} if kwargs is None else kwargs

    def start(self):
        _thread.start_new_thread(, ())

    def run(self):*self.args, **self.kwargs)[/python]

But not work with this example code...

Traceback (most recent call last):
  File "", line 237, in <module>
  File "", line 12, in start
TypeError: function missing 1 required positional arguments


[File "", line 237, in <module>]

mythread.start()                                  # ...Start the thread, run method will be invoked

[File "", line 12, in start]

_thread.start_new_thread(, ())



Forum Jump:

Users browsing this thread: 1 Guest(s)