Python Forum
Multithreading with ssh connection
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multithreading with ssh connection
#1
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.

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.
Reply


Messages In This Thread
Multithreading with ssh connection - by harusin - Jul-06-2017, 11:36 AM
RE: Multithreading with ssh connection - by Larz60+ - Jul-06-2017, 03:00 PM
RE: Multithreading with ssh connection - by harusin - Jul-07-2017, 05:24 AM
RE: Multithreading with ssh connection - by Larz60+ - Jul-07-2017, 10:52 AM
RE: Multithreading with ssh connection - by harusin - Jul-10-2017, 10:07 AM
RE: Multithreading with ssh connection - by Larz60+ - Jul-10-2017, 10:57 AM
RE: Multithreading with ssh connection - by harusin - Jul-10-2017, 11:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  multithreading Hanyx 4 1,322 Jul-29-2022, 07:28 AM
Last Post: Larz60+
Question Problems with variables in multithreading Wombaz 2 1,324 Mar-08-2022, 03:32 PM
Last Post: Wombaz
  Serial connection connection issue Joni_Engr 15 8,048 Aug-30-2021, 04:46 PM
Last Post: deanhystad
  Multithreading question amadeok 0 1,778 Oct-17-2020, 12:54 PM
Last Post: amadeok
  How can i add multithreading in this example WoodyWoodpecker1 3 2,510 Aug-11-2020, 05:30 PM
Last Post: deanhystad
  matplotlib multithreading catosp 0 2,949 Jul-03-2020, 09:33 AM
Last Post: catosp
  Multithreading dynamically syncronism Rodrigo 0 1,534 Nov-08-2019, 02:33 AM
Last Post: Rodrigo
  Locks in Multithreading Chuonon 0 1,845 Oct-03-2019, 04:16 PM
Last Post: Chuonon
  multithreading issue with output mr_byte31 4 3,199 Sep-11-2019, 12:04 PM
Last Post: stullis
  Multithreading alternative MartinV279 1 2,786 Aug-01-2019, 11:41 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020