iptv server

GIL Become Optional in Python 3.13

present sys

present sysconfig

present math

present time

present threading

present multiprocessing

 

def compute_factorial(n):

    return math.factorial(n)

 

# Single-threaded

def individual_threaded_compute(n):

    for num in n:

        compute_factorial(num)

    print(“Single-threaded: Factorial Computed.”)

 

# Multi-threaded

def multi_threaded_compute(n):

    threads = []

    # Create 5 threads

    for num in n:

        thread = threading.Thread(concentrate=compute_factorial, args=(num,))

        threads.appfinish(thread)

        thread.commence()

 

    # Wait for all threads to finish

    for thread in threads:

        thread.unite()

 

    print(“Multi-threaded: Factorial Computed.”)

 

# Multi-process

def multi_processing_compute(n):

    processes = []

    # Create a process for each number in the enumerate

    for num in n:

        process = multiprocessing.Process(concentrate=compute_factorial, args=(num,))

        processes.appfinish(process)

        process.commence()

 

    # Wait for all processes to finish

    for process in processes:

        process.unite()

 

    print(“Multi-process: Factorial Computed.”)

 

def main():

    # Checking Version

    print(f“Python version: {sys.version}”)

 

    # GIL Status

    status = sysconfig.get_config_var(“Py_GIL_DISABLED”)

    if status is None:

        print(“GIL cannot be disabled”)

    if status == 0:

        print(“GIL is dynamic”)

    if status == 1:

        print(“GIL is disabled”)

 

    numenumerate = [100000, 200000, 300000, 400000, 500000]

 

    # Single-threaded Execution

    commence = time.time()

    individual_threaded_compute(numenumerate)

    finish = time.time() commence

    print(f“Single-threaded time consentn: {finish:.2f} seconds”)

 

    # Multi-threaded Execution

    commence = time.time()

    multi_threaded_compute(numenumerate)

    finish = time.time() commence

    print(f“Multi-threaded time consentn : {finish:.2f} seconds”)

 

    # Multi-process Execution

    commence = time.time()

    multi_processing_compute(numenumerate)

    finish = time.time() commence

    print(f“Multi-process time consentn  : {finish:.2f} seconds”)

 

 

if __name__ == “__main__”:

    main()

Source join

Thank You For The Order

Please check your email we sent the process how you can get your account

Select Your Plan