控件没有返回主线程

时间:2017-10-06 09:43:36

标签: python multithreading

我编写了一个python程序,其中我在线程1中创建了一个UDP侦听器并尝试在线程2中执行某些操作。这里的问题是控件在线程1中被卡住并且它永远不会返回到主线程,所以线程2是甚至没有开始。

import threading
import socket
import time

data = ''

def ListenerUDP():
    sock1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    server_address1 = ('localhost', 5000)
    print('starting up UDP server on %s port %s' % server_address1)
    sock1.bind(server_address1)

    while True:
        print('\nUDP server is now listening up')
        data, address = sock1.recvfrom(4096)
        print('received %s bytes from %s' % (len(data), address))
        print('is %s' % data.hex())


def Forwarder():
    print('do something')


print('Starting main thread')

t1 = threading.Thread(target=ListenerUDP)
t1.start()

t2 = threading.Thread(target=Forwarder)
t2.start()

有人可以帮忙修理它。

0 个答案:

没有答案