Timeout::Error exception in a loop

DeliciousPie

I have this piece of ruby code in a loop:

pid = Process.spawn("my_process_command")
begin
    Timeout.timeout(16) do
        `my_timeout_command`
        Process.wait(pid)
    end
rescue
    system("clear")
    puts 'Process not finished in time, killing it'
    Process.kill('TERM', pid)
end

The problem is that once the Timeout::Error exception has been caught the block will be skipped and the loop does practically nothing. How can I fix this?

Uri Agassi

You need to rescue specifically for Timeout:Error since Timeout::Error is not a standard error:

pid = Process.spawn("my_process_command")
begin
    Timeout.timeout(16) do
        `my_timeout_command`
        Process.wait(pid)
    end
rescue Timeout::Error
    system("clear")
    puts 'Process not finished in time, killing it'
    Process.kill('TERM', pid)
end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Caught TimeOut Exception

From Dev

Eclipse giving Error "Unhandled event loop exception" No more handles

From Dev

JavaScript : For loop with timeout

From Dev

Catching the exception tracebacks in a loop and then raising the error(s) at the end of the script

From Dev

For Loop and Sequential Timeout

From Dev

Error when adding a timeout command to while loop in bash

From Dev

ServiceStack PooledRedisClient Timeout exception

From Dev

IOS 8.1 Safari:$.ajax giving timeout error dom exception 23

From Dev

"rescue Exception" not rescuing Timeout::Error in net_http

From Dev

WCF Timeout Exception Server Side

From Dev

Catching a WCF Timeout Exception

From Dev

Java - TIMEOUT (Infinite loop) error

From Dev

Unable to capture the transfer_timeout error in PL/SQL exception handler

From Dev

Timeout Exception with Spring Data Jpa

From Dev

Pass while loop to timeout

From Dev

Loop On Exception

From Dev

Selenium Timeout Exception python

From Dev

Selenium Timeout Exception in Python

From Dev

Catching the exception tracebacks in a loop and then raising the error(s) at the end of the script

From Dev

Error when adding a timeout command to while loop in bash

From Dev

Adding custom error message once Exception called within a loop

From Dev

DataGridView to XDocument Exception Error using foreach loop

From Dev

handle timeout exception in loopj

From Dev

Timeout exception in sqlite

From Dev

Javascript Timeout between for loop?

From Dev

Selenium Not Catching Timeout Exception

From Dev

App sudden got a Timeout exception and Internal server error

From Dev

PostAsync timeout / exception behaviour

From Dev

How to get the full information of runtime error instead of <Timeout exceeded getting exception details>?

Related Related

  1. 1

    Caught TimeOut Exception

  2. 2

    Eclipse giving Error "Unhandled event loop exception" No more handles

  3. 3

    JavaScript : For loop with timeout

  4. 4

    Catching the exception tracebacks in a loop and then raising the error(s) at the end of the script

  5. 5

    For Loop and Sequential Timeout

  6. 6

    Error when adding a timeout command to while loop in bash

  7. 7

    ServiceStack PooledRedisClient Timeout exception

  8. 8

    IOS 8.1 Safari:$.ajax giving timeout error dom exception 23

  9. 9

    "rescue Exception" not rescuing Timeout::Error in net_http

  10. 10

    WCF Timeout Exception Server Side

  11. 11

    Catching a WCF Timeout Exception

  12. 12

    Java - TIMEOUT (Infinite loop) error

  13. 13

    Unable to capture the transfer_timeout error in PL/SQL exception handler

  14. 14

    Timeout Exception with Spring Data Jpa

  15. 15

    Pass while loop to timeout

  16. 16

    Loop On Exception

  17. 17

    Selenium Timeout Exception python

  18. 18

    Selenium Timeout Exception in Python

  19. 19

    Catching the exception tracebacks in a loop and then raising the error(s) at the end of the script

  20. 20

    Error when adding a timeout command to while loop in bash

  21. 21

    Adding custom error message once Exception called within a loop

  22. 22

    DataGridView to XDocument Exception Error using foreach loop

  23. 23

    handle timeout exception in loopj

  24. 24

    Timeout exception in sqlite

  25. 25

    Javascript Timeout between for loop?

  26. 26

    Selenium Not Catching Timeout Exception

  27. 27

    App sudden got a Timeout exception and Internal server error

  28. 28

    PostAsync timeout / exception behaviour

  29. 29

    How to get the full information of runtime error instead of <Timeout exceeded getting exception details>?

HotTag

Archive