Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

End python code after 60 seconds

Below there is some fully functioning code.

I am planning to execute this code through command line, however I would like it to end after 60 seconds.

Does anyone know the best way of going about this?

Thanks in advance.

import time class listener(StreamListener): def on_data(self, data): try: print data saveFile = open('twitDB.csv','a') saveFile.write(data) saveFile.write('\n') saveFile.close() return True except BaseException, e: print 'failed ondata,' ,str(e) time.sleep(5) def on_error(self, status): print status 
user3102640
  • 39
  • 1
  • 1
  • 5