Python Threading inside a class

前端 未结 3 543
鱼传尺愫
鱼传尺愫 2020-12-02 09:09

I recently started with python\'s threading module. After some trial and error I managed to get basic threading working using the following sample code given in most tutoria

3条回答
  •  难免孤独
    2020-12-02 09:48

    I'm fairly certain that you can't make a single function threaded.

    The whole class will be threaded (sort of). When you instantiate the object, its __init__ will be called on another thread, and then when you call start() on that object, its run() will be called once, on another thread.

    So, if you have a TASK that needs to be on its own thread (disc IO, socket listening, etc), then you need a class to handle that task.

    @ndpu's answer solves your scope/access problems.

提交回复
热议问题