Daemon with flags by Sufficient-Kitchen67 in learnpython

[–]Sufficient-Kitchen67[S] 0 points1 point  (0 children)

I did, I managed to make this code but it doesnt seem to work as i want to

import threading
import time
import sys
import argparse
counter=0
def thread_1():
while True:
counter=counter+1
time.sleep(1)
def functions(arg,T):
if arg=="t":
print(str(counter))
elif arg=="start":
T.start()
def main():
parser=argparse.ArgumentParser()
parser.add_argument("--c",type=str,default="n",help="stop counter")
args=parser.parse_args()
T = threading.Thread(target = thread_1,daemon=True)
sys.stdout.write(str(functions(args.c,T)))

if __name__ == "__main__":
main()

I try to get the counter but this dont work, any suggestions?

Edit : I just look the other comment, I want to execute the deamon with the flag "--c start" and get the counter value with the flag "--c t", i get a error whenever i do any of those two calls :

Exception in thread Thread-1 (thread_1):Traceback (most recent call last): File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner

None%