I'm try to grab bullet screens by python. The process is that I will get the response after sending login and some others messages to bullet screens server.
When I plan to grab two rooms's bullet screens, I can only get the response of the first request.
Code is like this:
# coding=utf-8
import multiprocessing
import socket
import time
import re
import signal
import threading
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostbyname("openbarrage.douyutv.com")
port = 8601
client.connect((host, port))
def send_req_msg(msg):
"""
wrap msg
"""
pass
def set_msg(roomid):
msg = 'type@=loginreq/roomid@={}/\0'.format(roomid)
send_req_msg(msg)
msg_more = 'type@=joingroup/rid@={}/gid@=-9999/\0'.format(roomid)
send_req_msg(msg_more)
if __name__ == '__main__':
pool = []
roomid = [123, 666]
for i in range(0, len(roomid)):
t = threading.Thread(target=set_msg(roomid[i]))
t.start()
pool.append(t)
for a in pool:
a.join()
Both multiprocessing and threading can't succeed. As I use wireshard to analysis the tcp. There is only the first request and it's response. Also I can only get the room's screen bullets of 123. So why the second thread/processing doesn't work? And what should I do? Thanks.
send_req_msg()was called 4 times with different arguments so that's correct. If you think messages aren't sent try to print response from server after sending message if there's any.clientwon't work - the whole python file is re-executed so the second instance will get a different client connection. Look at the help 16.6.3.2 in this page docs.python.org/2/library/multiprocessing.html. AFAICT when using Multiprocessing, properly and completely reading and understanding the manual pages is critical for success.