我是python多线程的绝对初学者。我的应用程序需要远程登录200台服务器,执行命令并返回响应。我已经创建了用于远程登录和处理响应的单独的类。我了解了线程中的GIL和竞争条件,但不确定它们是否会对我的代码产生影响。因为我为每个线程创建类的新实例并访问该方法。因此从技术上讲线程不会共享相同的资源。谁能解释我的假设是否正确,否则请解释正确的做法?
主要方法:
if __name__ == "__main__":
thread_list = []
for ip in server_list: # server list contains the IP of hosts
config_object = Configuration () # configuration class has method for telnet device
thread1 = threading.Thread(target=config_object.captureconfigprocess,args=(ip))
thread_list.append(thread1)
for thread in thread_list:
thread.start()
for thread in thread_list:
thread.join()