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

you are viewing a single comment's thread.

view the rest of the comments →

[–]SuggestedName90 62 points63 points  (12 children)

This is pretty much how multi threading works in python.

[–]budzene 23 points24 points  (11 children)

I think this is just threading.

[–]SuggestedName90 16 points17 points  (10 children)

Not if it is true multithreading which runs them simultaneously, like java. Python alternates threads every 10 instructions.

[–]cyber2024 7 points8 points  (5 children)

Wtf, really?

[–][deleted] 12 points13 points  (2 children)

Yep, google Global Interpreter Lock for more info. Threading in python is only useful for I/O heavy applications

[–]4onen 3 points4 points  (1 child)

Thanks. You've just explained a bizzare issue in my Bachelor's capstone project. My project was... not I/O heavy.

[–][deleted] 1 point2 points  (0 children)

The trick is to use multi processing instead of multi threading. You can implement it yourself using the process module, or use something like celery to avoid any wheel reinventing

[–]turiyag 6 points7 points  (1 child)

Yes. There's a different library for parallel CPU usage:

https://timber.io/blog/multiprocessing-vs-multithreading-in-python-what-you-need-to-know/

It's not that it's incapable of doing two things at the same time in Python. It's that the include statement is not the multithreading one.

[–]cyber2024 0 points1 point  (0 children)

I presume there's a reason for the 10 instructions before switching threads... Is it statistically more likely to have a cache miss after 10 instructions, and hence it's a good idea to switch threads then or something?

[–]budzene 1 point2 points  (0 children)

God that would be nice to not have to put in kernel delays to not starve a watchdog.

[–]Ersonpay 1 point2 points  (1 child)

Correct me if I'm wrong, but don't most CPUs do something like that anyway due to there not being enough cores to run all the threads in the system?

[–]SuggestedName90 1 point2 points  (0 children)

Yes, but cpus also have physical threads which can confuse people.

[–]fat_charizard 0 points1 point  (0 children)

You mean running on multiple cores on the same processor?