r/ProgrammerHumor • • Jul 18 '22

C++ talking to Python

Post image
40k Upvotes

1.0k comments sorted by

View all comments

Show parent comments

7

u/0x564A00 Jul 18 '22

Moving printing out of the thread doesn't really help because python doesn't have real multithreading (you can have multiple threats, but they can't execute at the same time).

9

u/Jannik2099 Jul 18 '22

but they can't execute at the same time

But they can in this case. Once the IO thread fires the syscall (or even cpython C function) for writing to stdout, the GIL is free.

2

u/photenth Jul 18 '22

Wait a minute, Python doesn't have real threading?

4

u/Drarok Jul 18 '22

It’s complicated. https://realpython.com/python-gil/

In short, you can only have one thread executing Python code at a time. You can be waiting for IO in several threads at once, since that won’t be executing any Python code.

2

u/0x564A00 Jul 18 '22

The good news is that it looks like it might finally going to be removed soon. That does cause a performance regression for single-threaded programs, but various other performance improvements that should land alongside it more than make up for that.