Jump to content

Threads not dying when script is stopped


Camaro

Recommended Posts

So when I stop a script in the middle of a ConditionalLoop, the loop will continue well after the script has stopped. I can tell by text strings continually getting posted to the log that I call from inside the loop.

[INFO][Bot #1][01/08 11:19:59 PM]: Here
[INFO][Bot #1][01/08 11:19:59 PM]: Here
[INFO][Bot #1][01/08 11:19:59 PM]: Here
[WARN][Bot #1][01/08 11:20:01 PM]: Event executor is taking too long to suspend; terminating now...
[ERROR][Bot #1][01/08 11:20:01 PM]: Caught thread death in EventExecutor
[INFO][Bot #1][01/08 11:20:01 PM]: Script Copper miner has exited!
[INFO][Bot #1][01/08 11:20:43 PM]: Here
[INFO][Bot #1][01/08 11:20:43 PM]: Here
[INFO][Bot #1][01/08 11:20:44 PM]: Here

Are there certain steps I should take to properly stop a script?

Link to comment
Share on other sites

Do you create new Threads inside of onLoop? If so you'll need probably want to interrupt them by overring the script's onStop method. Alternatively, what you can do is use the script's async event system. I haven't used it personally, but if it's handholdy enough it'll track your Thread references for you and terminate them when the script ends.

Link to comment
Share on other sites

The API is horribly undocumented when it comes to internal stuff like this, so it's pretty much guess work. Try something like this:


/*
		 * ConditionalLoop isn't documented in the API.
		 * Parameters:
		 *  1. Bot
		 *  2. Some random unspecified integer that's perhaps the number of cycles
		 *     before the loop ends. 0 = infinite?
		 */
		new ConditionalLoop(bot, 0) {
			
			@Override
			public int loop() {
				
				// your code here...
				
				return // probably -1 or 0 to stop, then anything else = sleep time?
			}
		};

Hopefully, by specifying the 'bot', the conditional loop will pause/suspend/die when the script does too, because you can find that out from the bot:

private boolean isScriptRunning() {
		return bot.getScriptExecutor().isRunning();
	}

 

Edited by liverare
Link to comment
Share on other sites

    @Override
    public int onLoop() throws InterruptedException {
        new ConditionalLoop(bot, 30000) {

            @Override
            public int loop() {

                log("Running");

                return 300;
            }

            @Override
            public boolean condition() {
                return true;
            }

        }.start();
        return 600;
    }

Just a simple conditional. Goes way past the 30 second timeout

 

It is probably better to use an Event anyway. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...