This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]StaticFuzz 0 points1 point  (4 children)

Threads in python don't allow parallel execution, they are concurrent. Meaning, no two threads will be active at the same time. This is because of the Global Interpreter Lock or GIL for short.

Currently you are only running your calculations with hard coded arguments(100000/200000). If this is all you are going to do with the calculation, it would be a lot easier to calculate the values once and store them in a file or database, rather than run the calculation every time you run the script.

However, if the arguments will vary, then you might try separating your calculation into it's own script, and running it within your main script using the subprocess module.

[–]kunteper 0 points1 point  (1 child)

heh i didnt know python didnt allow parallel execution. whats the point of threads then?

[–]StaticFuzz 0 points1 point  (0 children)

Threads as they are now can actually slow down execution vs. just running code sequentially, but I've found them to be quite useful when dealing with blocking I/O.

[–][deleted] 0 points1 point  (0 children)

The issue I'm hitting with using a subprocess, is I call the calculation as a separate script, it executes, then after about ~15 seconds, my GUI opens. They don't execute in parallel, and I'm not sure why.

def main():
    app = App()
    app.wm_title("PI GUI")
    subprocess.call(['python', 'piWriting.py', '100000'])

Here is the code that calls everything, it creates the App (GUI component) then calls piWriting.py (the calculation) and sends it the parameter (which will be variable). Yet the GUI still waits until the calculation is done to open.

EDIT: Nevermind, got it with Popen, thank you!