multiprocessing initialising a function in a class

て烟熏妆下的殇ゞ 提交于 2019-12-24 14:13:51

问题


I am trying to initialise a function in a class using multiprocessing, by calling it from a function, which is inside the same same class

    def Streaminit(self,_track):
        self.twitterStream = tweepy.Stream(self.auth, Twitterapi.Listener())
        self.twitterStream.filter(track=_track)

    def Stream(self,track=""):
        self.streamobj = multiprocessing.Process(target = self.Streaminit(),args=(track,))

but when I call stream it raises an error

TypeError: Streaminit() takes exactly 2 arguments (1 given)

What am I doing wrong in this


回答1:


self.streamobj = multiprocessing.Process(target = self.Streaminit(),args=(track,))

You're calling the Streaminit function here with no arguments, and it takes one argument (plus self). So naturally it'll cause an error.

What it looks like you wanted to do was pass the function itself to multiprocessing.Process:

self.streamobj = multiprocessing.Process(target=self.Streaminit, args=(track,))


来源:https://stackoverflow.com/questions/33712787/multiprocessing-initialising-a-function-in-a-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!