The following code works fine but gives a warning in PyCharm as follows:
Unresolved attribute reference 'join' for class 'int':16
I understand what the warning is and why it's occurring, but I wonder if there's a better way to do this to remove the warning. If I could 'type' ss for example so the IDE would understand what's happening. Normally the thread code is in another module and is accessed by main and I'd rather main didn't have to know anything about 'ss.'
import time
import threading
ss=0
keepgoing=True
def fstart():
global keepgoing, ss
ss=threading.Thread(target=tmod)
ss.start()
keepgoing=True
def fstop():
global keepgoing
keepgoing=False
ss.join()
def tmod():
x=0
while keepgoing:
time.sleep(2)
print(str(x))
x+=1
if x==10 : x=0
def main():
print('Start')
fstart()
time.sleep(15)
fstop()
print('Done')
main()
It's a warning because you define ss
to be an integer by setting it to 0
at the top. You can turn it off by using the correct type hint. Replace the following line:
ss=0
with
ss: threading.Thread