2 years ago

#32689

test-img

Kasheef Ali

Using built in methods in executor.map

I am making a tkinter GUI to ping IPs or multiple Ips at the same time. I have use concurrent futures library to achieve concurrency but after using executor.map() I am unable to use the built in method of python ping library. I don't know if I am doing something wrong.If anyone is familiar with this please guide me.

`
def get_ping2():
    IP =[]
    result = ip_addr.get()
    IP= result.split()
    
    print(IP)
    with ThreadPoolExecutor() as executor:
        tasks = list(executor.map(ping,IP))
    with open('ping_result.json') as json_file:
        data = json.load(json_file)
    data['pingData'].append({
    'ip': str(ip_addr.get()),
    'date': str(datetime.now()),
    'avg_ms': str(tasks)
    })
    insertPingDataDynamic(data['pingData'][len(data['pingData'])-1])
    with open('ping_result.json', 'w') as outfile:
        json.dump(data, outfile)
    m_label['text'] = str(tasks)
    m_label['style'] = "Success.TLabel"`

before using the concurrent future the Gui looks like this GUI

` 

def get_ping():
    result = ping((ip_addr.get()), verbose=True)
    with open('ping_result.json') as json_file:
        data = json.load(json_file)
    data['pingData'].append({
    'ip': str(ip_addr.get()),
    'date': str(datetime.now()),
    'avg_ms': str(result.rtt_avg_ms)
    })
    insertPingDataDynamic(data['pingData'][len(data['pingData'])-1])
    with open('ping_result.json', 'w') as outfile:
        json.dump(data, outfile)
    m_label['text'] = str(result)
    m_label['style'] = "Success.TLabel"
`

Here I am saving the avg ping response by using .rtt_avg_ms method of pythonping library but after using concurrent library its not working and the GUI is saving the whole response instead of avg response Multiping

python

tkinter

python-multithreading

concurrent.futures

0 Answers

Your Answer

Accepted video resources