ADVERTISEMENT
ADVERTISEMENT

Python threading Module | stack_size() Method with Example

Python threading.stack_size() Method: Here, we are going to learn about the getName() method of threading Module in Python with its definition, syntax, and examples.
Submitted by Hritika Rajput, on May 14, 2020

Python threading.stack_size() Method

stack_size() is an inbuilt method of the threading module in Python. It is used to return the thread stack size needed while creating new threads.

Module:

    import threading

Syntax:

    stack_size([size])

Parameter(s):

  • size: It is an optional parameter, which specifies the stack size to be used for subsequently created threads. Its value must be 0 or any positive integer; the default value is 0.

Return value:

The return type of this method is <class 'int'>, it sets the stack size for a thread to be used while creating new threads.

Example:

# Python program to explain the use of 
# stack_size()  method in Threading Module

import time
import threading

def thread_1(i):
    time.sleep(5)
    print("Value by Thread-1:",i)
    print()

def thread_2(i):
    time.sleep(4)
    print("Value by Thread-2:",i)
    print()
    
def thread_3(i):
    print("Value by Thread-3:",i)
    print()
    
def thread_4(i):
    time.sleep(1)
    print("Value by Thread-4:",i)
    print()        

# Creating sample threads 
thread1 = threading.Thread(target=thread_1, args=(100,))
thread2 = threading.Thread(target=thread_2, args=(200,))
thread3 = threading.Thread(target=thread_3, args=(300,))
thread4 = threading.Thread(target=thread_4, args=(400,))

print(threading.stack_size())

# Starting the threads
thread1.start()
thread2.start()
thread3.start()
thread4.start()

Output

0
Value by Thread-3: 300

Value by Thread-4: 400

Value by Thread-2: 200

Value by Thread-1: 100
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.