Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Threads not dying when script is stopped

Featured Replies

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?

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.

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

  • Author
    @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. 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.