python - How can I exit a Python3 script after 5 minutes -


i have script copying data sd card. due huge amount of files/filesize, might take longer period of time expected. exit script after 5 minutes. how can so?

it's hard verify work without example code, try this, using signal module:

at beginning of code, define handler alarm signal.

import signal  def handler(signum, frame):     print 'times up! exiting..."     exit(0) 

before start long process, add line code:

#install signal handler signal.signal(signal.sigalrm, handler)  #set alarm 5 minutes signal.alarm(300) 

in 5 minutes, program receive alarm signal, call handler, exit. can other things in handler if want.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -