Sometimes we have a function running too long more than we expect, we want to kill it after a certain time. For example, we have a function connecting to a remote share, the function we use to connect does not provide a timeout or we can’t change its timeout.

Our solution is to build a timeout function to kill the function if it runs too long. I found this good and simple code:

How do i use it?