0

I am logging information in a tree view widget using ttk. From the information in each entry of the tree view, I am attempting to pass it to functions that use a selenium web driver to automate user actions. It is very important that the functions that access the webpage run concurrently.

def startTasks(click):
    tasks = tv4.get_children() #the tasks logged in the treeview
    for item in tasks:  
        taskInfo = tv4.item(item)
        thread = Thread(target=masterFunction, args=(taskInfo,))
        thread.start()
        thread.join()

the master function is as follows

def masterFunction(task):
    foo = {'site': task['text'], 'user': task['values'][0], 'pass':  task['values'][1], 'size':  str(task['values'][3])
        , 'link':  task['values'][2], 'proxy':  task['values'][4]}

    if (foo['site'] == 'site 1'):
        site1(foo)
    if (foo['site'] == 'site 2'):
       site2(foo)
    if (foo['site'] == 'site 3'):
        site3(foo)
    if (foo['site'] == 'site 4'):
        site4(foo)
    if (foo['site'] == 'site 5'):
        site5(foo)
    if (foo['site'] == 'site 6'):
       site6(foo)
    if (foo['site'] == 'site 7'):
        site7(foo)

the functions that are called 'siteX' are simpily functions that use the selenium web driver to carry out processes. How do I fix the problem of only 1 driver running sequentially when I want them to run concurrently?

1 Answer 1

1

Seems to me like the problem is this line - thread.join(): this causes your program to wait for the thread to end execution, thus your program does not run concurrently. Remove this line.

You should, however, use thread.join method, when your main thread(the main python program) ends, if you don't want the threads to just close forcefully. This would tell your program to wait for them to finish.

Also, if I may suggest:

functions_dict = {'site 1': site1, 'site 2': site2, 'site 3': site3....}
functions_dict[foo['site']]()

This saves all the ifs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.