I am trying to use threading in one of my features of a class. The class is not inheriting the Thread class, it is just making use of it, calling a function in the class. The code has been refined to the problem of my class.
The problem that occurs seems to be the implementation of using threads in a class and recursively calling a method? This is just my guess, I',m not a expert in python schemes so I don't know.
Set the thread variable in the method run to enable threading.
import threading
class Alpha:
# Set variable defaults
leader = 'Swansonburg'
# - Thread variables
MAX_CONNECTIONS = 5
lock = threading.BoundedSemaphore(value=MAX_CONNECTIONS)
def __init__(self, leader=''):
if (leader): self.leader = leader
def run(self):
print "[+] Alpha: %s, Calling For Backup!" % self.leader
self.ETA = 101
for percent in range(self.ETA):
""" SET TRUE TO ENABLE THREADING """
THREADING = False
self.lock.acquire() # Set thread cap
if (not THREADING):
self.CallBackup(percent)
else:
t = threading.Thread(target=self.CallBackup, args=(percent))
t.start()
def CallBackup(self, percent):
if (percent == 0): pass
elif (percent % 10 == 0) | (percent == 100):
output = ("=" * percent) + (" %% - %d" % percent)
print (output)
self.lock.release()
def main():
new_team = Alpha()
new_team.run()
if (__name__ == '__main__'):
main()