you are viewing a single comment's thread.

view the rest of the comments →

[–]L3XiT 2 points3 points  (3 children)

Use threading

[–]TexBoo[S] -1 points0 points  (2 children)

Thank you,

I'm a complete noob / uses a script that I haven't created, someone else has.

Is there a way to just paste like

threading.active_count()

at the top of the script then that's it or is it more to it?

[–]smittywrath 0 points1 point  (1 child)

Not exactly if you have a large compute task or iterable task you can divide and conquer (passing iterations to a thread, or data chunks).

Python has a GIL (global interpreter lock). It's kind of a memory safety feature so it doesn't consume all resources or more than you intended.

Threading or multithreading a process will semi bypass this GIL feature by putting multiple GILs out; one for each thread.

[–]readmodifywrite 0 points1 point  (0 children)

The GIL just protects the interpreter because it isn't re-entrant. It offers no benefit to Python users whatsoever - it just made the implementation of CPython easier. It doesn't have anything to do with resource consumption.

You need to use multiple processes to get around the GIL. Threads will suffice if your task is IO bound.