Justin G Justin G -4 years ago 85
Python Question

Restart my program in Python

I'm not sure why my code isn't working. I'm trying to restart my python application. Heres the function for restarting:

def restart_program():
p = psutil.Process(os.getpid())
for handler in p.get_open_files() + p.connections():
except Exception as e:

python = sys.executable
os.execl(python, python, *sys.argv)

I then called for it inside of an if statement like this:

if cycles >= CLEANCYCLES:
print('Cleaning database and re-logging...')
cur.execute('DELETE FROM oldposts WHERE id NOT IN (SELECT id FROM oldposts ORDER BY id DESC LIMIT ?)', [MAXPOSTS * 2])
cycles = 0

I ran it from CMD in python to see the error, and this is what it says:

raceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Users\suffICE\Desktop\redditBot\working version\csgoNAbot.py", line 91
TabError: inconsistent use of tabs and spaces in indentation

What do I do to fix this? When I remove calling for the sub, it works fine...

Answer Source

Your indentation is wrong. This error has nothing to do with restarting. Just fix it to use consistent spaces.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download