![]() |
|
Loop causes not responding[PYTHON] - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Python (https://sinister.li/Forum-Python) +--- Thread: Loop causes not responding[PYTHON] (/Thread-Loop-causes-not-responding-PYTHON) |
Loop causes not responding[PYTHON] - Guxi - 01-05-2013 Hello [username]. I made a GUI program for counterstrike 1.6, which protects players configuration from malicious "virus"/"bad configuration" that can be lunched by administrator on any server. You don't need to read the red text, but it won't kill you if you would. When admin "censures" you, instantly new file called "censuree.cfg" is being downloaded to your CSTRIKE folder and changes your original configuration to chaos. The way to get out of that "censure" is simply by deleting censuree.cfg and replacing your config.cfg with new one. Anyway.. my code has to loop and i made a delay with time.sleep(6) Which will pause my program for 6 seconds, so i could prevent it from 'not responding' BUT, according to my friends who tested it ( including me) they still got 'not responding' But program still works ( function of program ). Problem is that there is no way you can stop it excluding by ending the process or making force exit.. Do you know how i could make a better delay, so it doesn't freeze ( I also don't want to increase length of delay) :/? Heres is the code in my program that's main function, also when started causes freezing but works. Code: def activated1():
cstrikefolder = cstrike.get() # Gets the value of user input ( his cstrike folder path)
dir = os.getcwd() # Gets current part of working directory
time.sleep(6) # <--Main problem. This should make delay to prevent freezing
if os.path.isfile(cstrikefolder+"\censuree.cfg"): #Checks if censuree.cfg exists
os.remove(cstrikefolder+"\censuree.cfg") # If it does exist then remove it ( censuree.cfg )
shutil.copy2(dir+'\config.cfg', cstrikefolder+"\config.cfg") # And also copy the config.cfg from working directory ( replacing good confing with bad one)
activated1()
else:
activated1()RE: Loop causes not responding[PYTHON] - Guxi - 01-07-2013 Still hot thread for me.. BUMP RE: Loop causes not responding[PYTHON] - H4R0015K - 01-07-2013 the loop is (maybe) infinite which is causing it to freeze. RE: Loop causes not responding[PYTHON] - Guxi - 01-07-2013 (01-07-2013, 02:04 PM)H4R0015K Wrote: the loop is (maybe) infinite which is causing it to freeze. Yes, true.. only way to exit it is by clicking on other button "stop" which will start another function. But i still made a delay in that loop with time.sleep(6) <- which will pause it for 6 seconds.. Shouldn't that prevent it from freezing? RE: Loop causes not responding[PYTHON] - Deque - 01-07-2013 I don't do Python, but if you have a GUI and you don't want it to freeze, you usually use threads for tasks that take long. sleep won't help, when it makes the thread sleep that renders the GUI. Stackoverflow states three ways to solve this: http://stackoverflow.com/questions/148963/keeping-guis-responsive-during-long-running-tasks Have a look at that. RE: Loop causes not responding[PYTHON] - Guxi - 01-07-2013 OH, thank you! You have no idea how much you helped.. I'm requesting mod to close this thread.. It's answered |