我想使用self参数对函数进行线程化

问题描述 投票:0回答:1

我想对该函数进行线程化,但是当self参数到位时不知道如何进行线程化。任何人都知道我该怎么做。我将不胜感激

这里是功能

def processinformation(self):
    app = App.get_running_app()
    session = requests.Session()
    self.notif_stream = session.get("**********************************" + app.displayname + "/.json", stream=True)
    for line in self.notif_stream.iter_lines():
        if line:
            print(json.loads(line))
            newline = ast.literal_eval(line.decode('utf-8'))
            for key, thevalue in newline.items():
                for key, value in thevalue.items():
                    self.notif = session.get("**********************************" + app.displayname + "/" + key + "/" + "notification" + "/.json")                          
                    self.notificationslist.adapter.data.extend([value])          
python multithreading python-multithreading
1个回答
0
投票

[好,我通常没有太多理由编写多线程Python程序,但这似乎可行:

#!/usr/bin/env python3

import threading

class MyTarget:
    def mymethod(self, arg1, arg2):
        print(f"MyTarget, {arg1} {arg2}")

if __name__ == '__main__':
    my_target = MyTarget()
    t = threading.Thread(target=my_target.mymethod, args=("X", "Y"))
    t.start()
    # NOTE: In any _real_ program, the main thread would do
    #  something else, concurrently with the new thread.
    t.join()
© www.soinside.com 2019 - 2024. All rights reserved.