# Can you set a process timeout

**URL:** <https://discourse.processing.org/t/can-you-set-a-process-timeout/43534>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [December 21, 2023, 9:16am UTC](https://discourse.processing.org/t/can-you-set-a-process-timeout/43534 "2023-12-21T09:16:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bask185](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bask185](https://discourse.processing.org/u/bask185)\
**Post date:** [December 21, 2023, 9:16am UTC](https://discourse.processing.org/t/can-you-set-a-process-timeout/43534/1 "2023-12-21T09:16:57Z")

</div>

I can succesfully invoke arduino-cli to build and upload programs to an arduino board.  
The problem that I am having, is that the upload process takes 2 minutes before a status is returned.

When I select the wrong board type the program AVRDUDE takes 10 upload attempts and it waits a rediculous amount of time in between attemps. The thing is… if the first attempt fails, all attempts will.

What I want is a timeout on the process. If the process does not return in… lets say 10 seconds, I want to kill the process and display that the upload process has failed and the program should move on. As my code is now, my entire application freezes for 2 minutes.

I tried the function waitFor() but it does not seem to work or do what I want…

```auto
        if( status == true )
        { status = false ;

            println("SUCCES") ;
            print("\r\nUPLOADING . . . ") ;

            command = arduinoCliPath + uploadCommand ;
            p = launch(command);
            if(!p.waitFor(10, TimeUnit.SECONDS)) { p.destroy(); }

            in = new BufferedReader(new InputStreamReader( p.getInputStream())); // extra debug stuff
            while ((line = in.readLine( )) != null)
            {
                if( line.contains("New upload port"))
                {
                    status = true ;
                }
            }
            if( status == true )
            {
                println("SUCCES") ;
            }
            else
            {
                println("FAILED") ;
            }
        }
        else
        {
            println("FAILED") ;
        }
    } 
    catch (RuntimeException e) {println("RuntimeException, it fails") ; }
    catch (IOException e) {println("IOException, it fails") ; }
    catch (InterruptedException e) {println("FAILED") ; }

```

Can I implement a timeout and ifso how should I do that?

Kind regards 🥃

Bas

---

<div class="post-metadata">

**Author:** ![bask185](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bask185](https://discourse.processing.org/u/bask185)\
**Post date:** [December 27, 2023, 8:20pm UTC](https://discourse.processing.org/t/can-you-set-a-process-timeout/43534/3 "2023-12-27T20:20:01Z")

</div>

Well I’d like to know how to start a process on the background and generate a timeout if the process does not complete in a certain amount of time.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 27, 2023, 8:41pm UTC](https://discourse.processing.org/t/can-you-set-a-process-timeout/43534/4 "2023-12-27T20:41:42Z")

</div>

Hello @bask185 ,

Consider using these:

- [thread() / Reference / Processing.org](https://processing.org/reference/thread_.html)
- [millis() / Reference / Processing.org](https://processing.org/reference/millis_.html)

`:)`
