The Wayback Machine - https://web.archive.org/web/20240901143014/https://github.com/python/cpython/issues/107730
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Time of a single thread -- A Per-Interpreter GIL -- is greater than the Time of a single thread -- GIL activated -- by 4 seconds is that okay ? python 3.12 #107730

Open
Mastering-Python-GT opened this issue Aug 7, 2023 · 1 comment
Labels
pending The issue will be closed if no feedback is provided topic-subinterpreters type-bug An unexpected behavior, bug, or error

Comments

@Mastering-Python-GT
Copy link

Mastering-Python-GT commented Aug 7, 2023

i wrote this simple code :

from test.support import interpreters
import time
from threading import Thread

def countdown():
    for i in range(50000000):
      pass

t1 = Thread(target=countdown)
start = time.time()
t1.start()
t1.join()
end = time.time()
print('Time of a single thread -- GIL activated -- : ', end - start)
t1 = Thread(target=countdown)
t2 = Thread(target=countdown)
t3 = Thread(target=countdown)
start = time.time()
t1.start()
t2.start()
t3.start()
t1.join()
t2.join()
t3.join()
end = time.time()
print('Time of a three threads -- GIL activated -- : ', end - start)

script='''
for i in range(50000000):
    pass
'''
def countdown2():
    interp = interpreters.create()
    interp.run(script)

tt1 = Thread(target=countdown2)
start = time.time()
tt1.start()
tt1.join()
end = time.time()
print('Time of a single thread -- A Per-Interpreter GIL -- : ', end - start)

tt1 = Thread(target=countdown2)
tt2 = Thread(target=countdown2)
tt3 = Thread(target=countdown2)
start = time.time()
tt1.start()
tt2.start()
tt3.start()
tt1.join()
tt2.join()
tt3.join()
end = time.time()
print('Time of three threads -- A Per-Interpreter GIL -- : ', end - start)

i got this results :

Time of a single thread -- GIL activated -- :  6.494914293289185 seconds
Time of a three threads -- GIL activated -- :  18.17412829399109 seconds
Time of a single thread -- A Per-Interpreter GIL -- :  10.804685592651367 seconds
Time of three threads -- A Per-Interpreter GIL -- :  9.959944486618042 seconds

The Time of a single thread -- A Per-Interpreter GIL -- is greater than the Time of a single thread -- GIL activated -- by 4 seconds is that okay ?

@Mastering-Python-GT Mastering-Python-GT changed the title The time of a single thread -- A Per-Interpreter GIL -- The Time of a single thread -- A Per-Interpreter GIL -- is greater than the Time of a single thread -- GIL activated -- by 4 seconds is that okay ? Aug 7, 2023
@Mastering-Python-GT Mastering-Python-GT changed the title The Time of a single thread -- A Per-Interpreter GIL -- is greater than the Time of a single thread -- GIL activated -- by 4 seconds is that okay ? The Time of a single thread -- A Per-Interpreter GIL -- is greater than the Time of a single thread -- GIL activated -- by 4 seconds is that okay ? python 3.12 Aug 7, 2023
@Eclips4
Copy link
Member

Eclips4 commented Aug 7, 2023

In countdown2 you create a new sub-interpreter, it's not "zero-cost operation", this takes some amount of time, so this works as expected.
Also, PEP 554 is not accepted yet.

Uh.. seems your benchmark is totally wrong. Why do you create a Thread in main interpreter, and then in this thread create a sub-interpreter? I believe, you want to create sub-intepreter, and run some threads in him.

@ericsnowcurrently ericsnowcurrently added the type-bug An unexpected behavior, bug, or error label Jun 18, 2024
@ericsnowcurrently ericsnowcurrently added the pending The issue will be closed if no feedback is provided label Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending The issue will be closed if no feedback is provided topic-subinterpreters type-bug An unexpected behavior, bug, or error
Projects
Status: Todo
Development

No branches or pull requests

4 participants