如何控制线程外的多个套接字? [英] How do I control multiple sockets outside of a thread?

查看:84
本文介绍了如何控制线程外的多个套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

线程调用的函数:

The function being called by threads:

def Spawn(asdas,asdasdasd):
    print asdasdas+' : '+asdasd
    s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect(('asdasd.tv',66442))
    s.send('PASS '+asdasd+'\r\n')
    s.send('NICK '+asdasdas+'\r\n')
    s.send('JOIN #adasd\r\n')
    while True:
        print(s.recv(5345345))





线程开始上升:



Were the threads start going up:

lines=tuple(open('data.txt', 'r'))
for line in lines:
    data=line.split(' ',1)
    t=threading.Thread(target=Spawn,args=(data[0].replace('\n',''),data[1].replace('\n','')))
    t.start()







我需要做的是




What I need to be able to do is

while True:
    cmd=raw_input('>> ')
    if(cmd.split(' ')[0]=="test"):
        print 'This is a test command'
    s.send('PRIVMSG #asdasd test\r\n')
    else:
        print 'Invalid command'</pre>



不起作用,因为它在此上下文中不存在


which doesn't work because it doesn't exist in this context

推荐答案

threading and raw input do not work together unless have something nowait/non blocking.

I advise to take a look at Gevent module.
Next time also unscramble your code, so we can see what your trying to do.
You can always leave the "security" parts out so long you put some pseudo example...or we can not help you.


这篇关于如何控制线程外的多个套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆