def get_and_dom(self): # print("cron start") # follows = self.w.get_user_follows() # for follow in follows: # if self.weibo_handle.dom_weibo_follow(follow): # print("已将微博账号的关注信息存入数据库") print("getting weibo from follows") w = WeiBo(self.username, self.password) weibo_handle = WeiboHandle(self.username, self.password) uids = weibo_handle.get_followed_from_database() q1 = Queue() q2 = Queue() for uid in uids: q1.put(uid) while not q1.empty(): uid = q1.get() t = MyThread(func=w.get_user_weibo, args=(uid,)) t.start() t.join() for data in t.get_result(): q2.put(data) while not q2.empty(): weibo = q2.get() t = MyThread(func=weibo_handle.dom_weibo, args=(weibo,)) t.start() t.join()
def runMainApp(): global textPath conf = { '/static': { 'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.dirname(__file__) + "/serve" } } # Create an instance of MainApp and tell Cherrypy to send all requests under / to it. (ie all of them) cherrypy.tree.mount(MainApp(), '/', conf) # Tell Cherrypy to listen for connections on the configured address and port. cherrypy.config.update({ 'server.socket_host': listen_ip, 'server.socket_port': listen_port, 'engine.autoreload.on': True, }) # Start the web server cherrypy.engine.start() global thread thread = MyThread() thread.daemon = True thread.start() # And stop doing anything else. Let the web server take over. cherrypy.engine.block()
from thread import MyThread # main if __name__ == '__main__': thread1 = MyThread() thread2 = MyThread() thread1.start() thread2.start()