33import numpy as np
44import socket
55import os
6+ import platform
67from _thread import *
78import glob
89
@@ -368,21 +369,23 @@ def process_response(response, connection, envs, enviroment, instance_id, close,
368369 return
369370 connection .close ()
370371
371- # while True:
372- # Client, address = ServerSocket.accept()
373- # print('Connected to: ' + address[0] + ':' + str(address[1]))
374- # start_new_thread(threaded_client, (Client, ))
375- # ThreadCount += 1
376- # print('Thread Number: ' + str(ThreadCount))
377- # ServerSocket.close()
378-
379-
380- # This is needed to make it work on MacOS. In fact, MacOS doesn't allow to rendere on threads
381- # other than the main thread
382- while True :
383- Client , address = ServerSocket .accept ()
384- print ('Connected to: ' + address [0 ] + ':' + str (address [1 ]))
385- ThreadCount += 1
386- print ('Thread Number: ' + str (ThreadCount ))
387- threaded_client (Client ) # Directly call the function without threading
388- ServerSocket .close ()
372+
373+ if __name__ == "__main__" :
374+ if platform .system () == 'Darwin' :
375+ # This is needed to make it work on MacOS. In fact, MacOS doesn't allow to rendere on threads
376+ # other than the main thread
377+ while True :
378+ Client , address = ServerSocket .accept ()
379+ print ('Connected to: ' + address [0 ] + ':' + str (address [1 ]))
380+ ThreadCount += 1
381+ print ('Thread Number: ' + str (ThreadCount ))
382+ threaded_client (Client ) # Directly call the function without threading
383+ ServerSocket .close ()
384+ else :
385+ while True :
386+ Client , address = ServerSocket .accept ()
387+ print ('Connected to: ' + address [0 ] + ':' + str (address [1 ]))
388+ start_new_thread (threaded_client , (Client , ))
389+ ThreadCount += 1
390+ print ('Thread Number: ' + str (ThreadCount ))
391+ ServerSocket .close ()
0 commit comments