Skip to main content

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.
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' 
edit:
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

Popular posts from this blog

Joomla 3.3 Installation Error message - Joomla! Forum - community, help and support

Multilanguage infinite redirect loop error. - Joomla! Forum - community, help and support

Thread: Wine can't find the cd