question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to interrupt a function call?

See original GitHub issue

I can’t seem to find a way to interrupt a running function.

Say you have an infinite while loop within a function

function x()
    while true do
        ... code
    end
end

And you run that function x (in my case by finding it in the bindings) by calling the call() method on it. Is there anyway to interrupt it?

I’m running the script in another thread so my UI doesn’t freeze. Usually there is an InterruptedException thrown whenever the thread gets interrupted with blocking methods but the call method doesn’t seem to throw such exception.

I’m currently just loading a custom library extending from the DebugLib class with an interrupt field so whenever a new line is processed and the interrupt state is true, the lib will throw a LuaError. But I wonder if there’s no simpeler solution to this?

Also the above “fix” doesn’t apply to infinite loops since it doesn’t detect infinite loops. You’d have to interrupt the running script which might not always work.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
orange451commented, Nov 30, 2020

This is a problem I tackled in my project. To solve the run-away while(true) scripts, I created my own class that extends DebugLib, and overrides the onInstruction method. In there, for a given script I keep track of how many instructions are sent through (a simple counter that does +=1).

For my purposes, 1.0e8 was enough of a threshold to throw a ScriptInterruptException, which is a custom exception that extends RuntimeException.

0reactions
Way911commented, Aug 11, 2021

This is a problem I tackled in my project. To solve the run-away while(true) scripts, I created my own class that extends DebugLib, and overrides the onInstruction method. In there, for a given script I keep track of how many instructions are sent through (a simple counter that does +=1).

For my purposes, 1.0e8 was enough of a threshold to throw a ScriptInterruptException, which is a custom exception that extends RuntimeException.

Instead of tracking count of instructions , I solved it by checking whether current thread is interrupted or not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to interrupt a function call in Java - Stack Overflow
A better alternative would be for your code to wait for the response for a certain amount of time and just abandon the...
Read more >
Can an interrupt function call a regular function?
The right answer is yes and no. The issue here is reentrancy : whether a function can be interrupted while it's being called...
Read more >
How to Proper Call an Interrupt within a Function - TI E2E
1. Think of an interrupt as a function, that runs any time an event happens regardless of what your program is doing. The...
Read more >
Function Calls in Interrupts
Hi, I read that functions should not be called in interrupts, and instead flags should be set. This would mean that an event...
Read more >
Calling a function inside interrupt - Arduino Forum
That being said, the general advice is to keep your ISRs short and simple. The best thing to do is to set a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found