How do i limit the amount of time a python script runs [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • Kill process with timeout

    1 answer



So i use a python scrips that sometimes on some ips it just hangs. I run the script on about 250 ips. With xargs from a sh script



How would i i limit the time of the py script runing. If it hang for more than 30 sec for example to leave/kill ?



I dont want to use time as it is server dependant.
I was thinking more of a python function







share|improve this question













marked as duplicate by Jeff Schaller, Jesse_b, Archemar, Kusalananda linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 3 at 18:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Here is a similar question: unix.stackexchange.com/questions/254457/…
    – dhag
    May 3 at 16:53










  • I want to limit the amount of food I eat, but I don’t want to monitor my food intake.  What?  If you don’t want to “use time”,  what is your question?
    – Scott
    May 3 at 22:20














up vote
0
down vote

favorite













This question already has an answer here:



  • Kill process with timeout

    1 answer



So i use a python scrips that sometimes on some ips it just hangs. I run the script on about 250 ips. With xargs from a sh script



How would i i limit the time of the py script runing. If it hang for more than 30 sec for example to leave/kill ?



I dont want to use time as it is server dependant.
I was thinking more of a python function







share|improve this question













marked as duplicate by Jeff Schaller, Jesse_b, Archemar, Kusalananda linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 3 at 18:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Here is a similar question: unix.stackexchange.com/questions/254457/…
    – dhag
    May 3 at 16:53










  • I want to limit the amount of food I eat, but I don’t want to monitor my food intake.  What?  If you don’t want to “use time”,  what is your question?
    – Scott
    May 3 at 22:20












up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • Kill process with timeout

    1 answer



So i use a python scrips that sometimes on some ips it just hangs. I run the script on about 250 ips. With xargs from a sh script



How would i i limit the time of the py script runing. If it hang for more than 30 sec for example to leave/kill ?



I dont want to use time as it is server dependant.
I was thinking more of a python function







share|improve this question














This question already has an answer here:



  • Kill process with timeout

    1 answer



So i use a python scrips that sometimes on some ips it just hangs. I run the script on about 250 ips. With xargs from a sh script



How would i i limit the time of the py script runing. If it hang for more than 30 sec for example to leave/kill ?



I dont want to use time as it is server dependant.
I was thinking more of a python function





This question already has an answer here:



  • Kill process with timeout

    1 answer









share|improve this question












share|improve this question




share|improve this question








edited May 3 at 21:33
























asked May 3 at 16:51









Killroy2018

346




346




marked as duplicate by Jeff Schaller, Jesse_b, Archemar, Kusalananda linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 3 at 18:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Jeff Schaller, Jesse_b, Archemar, Kusalananda linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 3 at 18:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • Here is a similar question: unix.stackexchange.com/questions/254457/…
    – dhag
    May 3 at 16:53










  • I want to limit the amount of food I eat, but I don’t want to monitor my food intake.  What?  If you don’t want to “use time”,  what is your question?
    – Scott
    May 3 at 22:20
















  • Here is a similar question: unix.stackexchange.com/questions/254457/…
    – dhag
    May 3 at 16:53










  • I want to limit the amount of food I eat, but I don’t want to monitor my food intake.  What?  If you don’t want to “use time”,  what is your question?
    – Scott
    May 3 at 22:20















Here is a similar question: unix.stackexchange.com/questions/254457/…
– dhag
May 3 at 16:53




Here is a similar question: unix.stackexchange.com/questions/254457/…
– dhag
May 3 at 16:53












I want to limit the amount of food I eat, but I don’t want to monitor my food intake.  What?  If you don’t want to “use time”,  what is your question?
– Scott
May 3 at 22:20




I want to limit the amount of food I eat, but I don’t want to monitor my food intake.  What?  If you don’t want to “use time”,  what is your question?
– Scott
May 3 at 22:20










1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










/path/to/job.py &
pid=$!
sleep 30
if kill -0 $pid; then kill -TERM $pid; fi





share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    /path/to/job.py &
    pid=$!
    sleep 30
    if kill -0 $pid; then kill -TERM $pid; fi





    share|improve this answer

























      up vote
      0
      down vote



      accepted










      /path/to/job.py &
      pid=$!
      sleep 30
      if kill -0 $pid; then kill -TERM $pid; fi





      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        /path/to/job.py &
        pid=$!
        sleep 30
        if kill -0 $pid; then kill -TERM $pid; fi





        share|improve this answer













        /path/to/job.py &
        pid=$!
        sleep 30
        if kill -0 $pid; then kill -TERM $pid; fi






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered May 3 at 16:58









        DopeGhoti

        40k54779




        40k54779












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Christian Cage

            How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?