调用正在运行的线程内的函数

时间:2015-10-27 06:18:05

标签: python multithreading

我有这段代码:

def Spawn(nick,password):
    Active=True

    s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect(('asdasd',asdasdasd))
    s.send('PASS '+password+'\r\n')
    s.send('NICK '+nick+'\r\n')
    s.send('JOIN '+channel+'\r\n')

    while True:
        buf=s.recv(1024)
        if('PRIVMSG' in buf):
            sender=buf.split('!',1)[0].split(':')
            message=buf.split(':',2)[2].replace('\n','')
            if(sender[1]==owner):
                if(sender[1]==owner):
                    if(message.strip()=='!stop'):
                        Active=False
                        print '('+nick+')'+' has been disabled'
                    else:
                        if(message.strip()=='!start'):
                            Active=True
                            print '('+nick+')'+' has been enabled'
                        else:
                            if(Active):
                                print 'sent'

lines=tuple(open('accts.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()

我需要能够在线程之外运行s.send('asdasdasd\r\n')但我无法找到关于此的更多信息

如果有可能我希望能够定义我想要调用该函数的线程

0 个答案:

没有答案