Jul-06-2017, 11:36 AM
Hello,
i need help with implementation Queue and maybe Lock in multithreading operation. Code below will print results i want, but i want to return it as object for further operations. if there is option to solve this with multiprocessing please how to apply it to this concrete code.
i need help with implementation Queue and maybe Lock in multithreading operation. Code below will print results i want, but i want to return it as object for further operations. if there is option to solve this with multiprocessing please how to apply it to this concrete code.
self.query_sort() ## Returns Dictionary with ip addresses scope {"9" : "192.168.9.0", "192.168.9.1", ....} it's about 400 IP's in 7 different scopes self.list_result = [] def get_network_data(self, ixx): for ix in ixx: sshh = SshConnection(ix, self.username, self.password) # Connecting to SSH ix is ip address try: out1, err1 = sshh.ssh_command("ioreg -c IOPlatformExpertDevice " "-d 2 | awk '/IOPlatformSerialNumber/'") # Get computer serial number serial_number = out1[0].strip().split('"') out2, err2 = sshh.ssh_command('echo $HOSTNAME') # Get computer name station_name = out2[0].strip().split(".")[0] new_rec = ix + ":" + serial_number[3] + ":" + station_name print(new_rec) # returns "192.168.9.1:DXXXXXXXXXX:MY_NAME" self.list_result.append(new_rec) # This will return None because writing to shared memory except: pass def thread_queue(self): dict_all = self.query_sort() for x in dict_all.values(): t = threading.Thread(target=self.get_network_data, args=(x,)) t.start()Thanks.