Thread: [Python] wait and notify
a program have 2 threads, 1 processing information , acts on it, other listen socket , deliver data received main thread. data shared between multiple hosts, when 1 host start sending should other start sending.
intention of code, send data every 5 s, can sooner if server socket receive data host.
edit:php code:main_thread
class serversocket(socketserver.baserequesthandler):
def handle(self):
data = self.request[0].strip()
global main_thread
# store data
main_thread.acquire()
main_thread.notify()
main_thread.release()
def main():
global main_thread
main_thread = threading.current_thread()
client = clientsocket()
server = socketserver.udpserver(('127.0.0.1', 22222), serversocket)
threading.thread(target=server.serve_forever).start()
while true:
main_thread.acquire() # cause exception
main_thread.wait(5)
main_thread.release()
# exception
attributeerror: '_mainthread' object has no attribute 'acquire'
solved changing this, using python 3
code:main_thread = threading.condition()
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] [Python] wait and notify
Ubuntu
Comments
Post a Comment