Jump to content
UBot Underground

[FREE PLUGIN] Threads Counter - UBot v4 Threading Fixed


Recommended Posts

I know it works...but I don't think that's efficient, since UI always needs to execute function that way vs. only reading variable (and I think that happens pretty often since UI is constantly updated)...

Good point though :-)

Link to post
Share on other sites
  • Replies 160
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

As you may be aware threading in UBot v4 is not safe and may not work as expect under certain conditions, which would result in threads slowly dying out, so at the end, you only get left with 1 active

Awesome plugin UBotDev

You are not using the plugin from the title, instead you are using the plugin that Blumi 40 keeps posting here (Blumi40, can you please open another thread for that plugin instead of discussing it her

Good point though :-)

Yeah, I don't think it's a good practice, so I always avoid that and always use variables there...

Link to post
Share on other sites

Thanks, my code is this:

ui drop down("Threads", "5,10,20,30,40,50", #INPUT Threads)
ui stat monitor("Threads (Active/Total):", "<b>{#THREADS Active}/{#THREADS Max}</b>")
comment("Total de la lista que va a ser navegada.")
ui stat monitor("COUNT:", #COUNT)
set(#THREADS Max, #INPUT Threads, "Global")
clear list(%PROXIES)
add list to list(%PROXIES, $list from text("http://alice.pandorabots.com/
http://botbench.com/
http://botpoet.com/
http://commons.wikimedia.org/wiki/User:Flickr_upload_bot
http://dictionary.reference.com/browse/bot
http://egg-bot.com/
http://en.wikipedia.org/wiki/Ben_Bot
http://en.wikipedia.org/wiki/Boe-Bot
http://en.wikipedia.org/wiki/Bot
http://en.wikipedia.org/wiki/Bot,_Tarragona
http://en.wikipedia.org/wiki/Bot_Colony
http://en.wikipedia.org/wiki/Bot_herder
http://en.wikipedia.org/wiki/Botfly
http://en.wikipedia.org/wiki/Botnet
http://en.wikipedia.org/wiki/Bots
http://en.wikipedia.org/wiki/Build%E2%80%93operate%E2%80%93transfer
http://en.wikipedia.org/wiki/Chatterbot
http://en.wikipedia.org/wiki/Computer_poker_players
http://en.wikipedia.org/wiki/Googlebot", $new line), "Delete", "Global")
set(#PROXIES ROW, 0, "Global")
set(#COUNT, $list total(%PROXIES), "Global")
if($comparison(#THREADS Max, ">", #COUNT)) {
    then {
        alert("You need to have more proxies than threads.")
        stop script
    }
    else {
    }
}
set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "reset"), "Global")
loop while($comparison(#COUNT, ">", 0)) {
    if($comparison($plugin function("Threads Counter.dll", "threads counter", "read"), "<", #THREADS Max)) {
        then {
            comment("Increment Number Of Threads And Store Value to UBot Variable.")
            set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "increment"), "Global")
            if($comparison(#PROXIES ROW, ">=", $list total(%PROXIES))) {
                then {
                    set(#PROXIES ROW, 0, "Global")
                }
                else {
                }
            }
            THREAD START(#PROXIES ROW)
            increment(#PROXIES ROW)
            decrement(#COUNT)
        }
        else {
            wait(0.2)
        }
    }
}
define THREAD START(#PROXIES ROW) {
    thread {
        in shared browser {
            SCRAPE WHATSMYIP(#PROXIES ROW)
        }
        set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "decrement"), "Global")
    }
}
set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "read"), "Global")
loop while($comparison(#THREADS Active, ">", 0)) {
    set(#THREADS Active, $plugin function("Threads Counter.dll", "threads counter", "read"), "Global")
    wait(2)
}
stop script
define SCRAPE WHATSMYIP(#PROXIES ROW) {
    navigate($list item(%PROXIES, #PROXIES ROW), "Wait")
    wait(20)
}

And a short video about the problem is http://www.screencast.com/t/yTKKBPdyfX

Are you sure that's all you changed? Please share your code, else it's almost impossible to help you.

Link to post
Share on other sites

Interesting...I've never noticed that but it looks like threading doesn't work with "shared browser" (I've never used it since I don't think it's a good idea...1 login+multiple threads). Although "$list item" returns the correct value navigate command just won't obey that and it will navigate to the page that started loading first (ignoring all other navigate commands that execute almost simultaneously).

 

However, if you really need it to work like that adding 1s delay after THREAD START() solved the problem here.

  • Like 1
Link to post
Share on other sites

Hey there it is... my new friend.. the one second delay to fix threading  :P

 

Sorry couldn't resist 

I had you in mind when giving the suggestion...I knew you'll like the solution. :) But really...couldn't find a better one (I think the problem is related to how shared browser works).

Link to post
Share on other sites
  • 4 months later...
  • 1 month later...

This doesn't seem to be working perfectly for me. Over time, the thread count goes off. for example i have 0 threads open now in which my bot should restart its function, but thread counter is on 1 so its stuck doing nothing. 

Link to post
Share on other sites

This doesn't seem to be working perfectly for me. Over time, the thread count goes off. for example i have 0 threads open now in which my bot should restart its function, but thread counter is on 1 so its stuck doing nothing. 

Hello. 

 

I tried to guess and visualize a little bit.. But I'm very sorry... I wasn't able to see your code in front of my eye's  :D

I think it would be helpful if you give us some more details.

 

Dan

Link to post
Share on other sites

This doesn't seem to be working perfectly for me. Over time, the thread count goes off. for example i have 0 threads open now in which my bot should restart its function, but thread counter is on 1 so its stuck doing nothing. 

 

Yeah, as Dan said, it's hard to help you without seeing any code... I didn't have any problems till now, so I'm not sure what could be wrong.

Link to post
Share on other sites

plugin command("HTTP post.dll", "http clear objects")
plugin command("LocalDictionary.dll", "clear global dictionary")
loop(99999999) {
Scrape Process()
set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "reset"), "Global")
set(#Loops, $list total(%UniqueUsers), "Global")
set(#ListItem, 0, "Global")
loop(#Loops) {
loop while($comparison(#ThreadCount, ">=", 10)) {
wait(1)
}
set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "increment"), "Global")
thread {
plugin command("LocalDictionary.dll", "init local dictionary")
plugin command("LocalDictionary.dll", "local dictionary add", "Target", $list item(%UniqueUsers, #ListItem))
Login()
set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "decrement"), "Global")
}
wait(1)
increment(#ListItem)
}
loop while($comparison($plugin function("Threads Counter.dll", "threads counter", "read"), ">", 0)) {
wait(5)
}
}
Link to post
Share on other sites

One know issue is that the script won't stop (although threads finished), so you need to put "stop" command at the end of the code.

 

Also, FYI, you should pass variable #ListItem through a define command (the code you have inside thread should be in that command/function) to ensure it stays unchanged during the thread lifetime. Else that variable may change before it's used inside the thread, meaning that you would be passing wrong data in there....

Link to post
Share on other sites

adding a stop wont work for me, because what i am doing is scraping 25 pages. then threading the process of posting on them. then when thread is back to 0. scrape next 25 pages. then thread to post on them. etc etc. 

 

plus, shouldnt thread count still be correct regardless? 

Link to post
Share on other sites

adding a stop wont work for me, because what i am doing is scraping 25 pages. then threading the process of posting on them. then when thread is back to 0. scrape next 25 pages. then thread to post on them. etc etc. 

 

Then you are not experiencing that problem (I guess you didn't read that post...the problem is related to part when bot reaches the end of script but won't stop).

You should still take that other suggestion into consideration...

 

Yes, threads should drop to 0.

 

I've stripped down your code a bit and threading itself works just fine (threads drop to 0 and alert is displayed), so I think you may have problems elsewhere. 

 

Here is the code:

loop(99999999) {
    set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "reset"), "Global")
    set(#Loops, 101, "Global")
    set(#ListItem, 0, "Global")
    loop(#Loops) {
        loop while($comparison(#ThreadCount, ">=", 10)) {
            wait(0.1)
        }
        set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "increment"), "Global")
        thread {
            set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "decrement"), "Global")
        }
        wait(0.1)
        increment(#ListItem)
    }
    loop while($comparison($plugin function("Threads Counter.dll", "threads counter", "read"), ">", 0)) {
        wait(5)
    }
    alert("")
}

What value does variable #Loops have on your side - are you opening too many threads?

Link to post
Share on other sites

Loops is the number of scraped posts ( usually between 20-30  )

Then you are not experiencing that problem (I guess you didn't read that post...the problem is related to part when bot reaches the end of script but won't stop).

You should still take that other suggestion into consideration...

 

Yes, threads should drop to 0.

 

I've stripped down your code a bit and threading itself works just fine (threads drop to 0 and alert is displayed), so I think you may have problems elsewhere. 

 

Here is the code:

loop(99999999) {
    set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "reset"), "Global")
    set(#Loops, 101, "Global")
    set(#ListItem, 0, "Global")
    loop(#Loops) {
        loop while($comparison(#ThreadCount, ">=", 10)) {
            wait(0.1)
        }
        set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "increment"), "Global")
        thread {
            set(#ThreadCount, $plugin function("Threads Counter.dll", "threads counter", "decrement"), "Global")
        }
        wait(0.1)
        increment(#ListItem)
    }
    loop while($comparison($plugin function("Threads Counter.dll", "threads counter", "read"), ">", 0)) {
        wait(5)
    }
    alert("")
}

What value does variable #Loops have on your side - are you opening too many threads?

Link to post
Share on other sites

As you can see in this video, the code I've posted above works fine, that's why I think there is nothing wrong with threading...I guess it may be your code/setup.

 

Does the code above work for you or not? What version of UBot are you using? Maybe you should share the whole code, since this part seems to work ok....

Link to post
Share on other sites

it works fine at the beginning but if you leave it running for a while ( after a few hours ) thats when the thread counter goes off

 

 

in one of my other bots, the thread counter sometimes even goes in the negative after a while.  

 

 

 

also, as for passing the list item in a define? why that instead of local dictionary? I thought local dictionary is thread safe?

Link to post
Share on other sites

I've been running bots with thread counter for days and I haven't noticed anything like that. I also left the code above running for some time an nothing.

 

Whatever you use you need to use define command to ensure that value you pass in doesn't changes when a new thread is about to start. Local dictionary being thread safe has nothing to do with this....

Link to post
Share on other sites

I changed it to use define like you said and it makes no difference. After hours of running, the thread counter ends up being off still. 

 

and the reason i said local dictionary is because you are sayuing define so that the value passed doesnt change, but local dictionary value shouldnt change either within the thread. 

Link to post
Share on other sites

Strange...I can't reproduce it so I can't do anything to help you....

 

Again, local dictionary has nothing to do with that....the problem is in UBot variable "#ListItem" that you are passing to thread, and that value can change for thread because you are not using define command.

 

EDIT: If you still need confirmation about define commands, Dan wrote a post about that recently: http://www.ubotstudio.com/forum/index.php?/topic/17292-info-biggest-mistake-with-threading/

Link to post
Share on other sites

The only thing I see is that you should read thread count with plugin on problematic places, not by reading UBot variable...refering to this line of code (#ThreadCount doesn't have up to date info on threads count):

loop while($comparison(#ThreadCount, ">=", 10)) {

If threads go down to negative values I'm sure you are decrementing thread counter more often than you should (you haven't shared the whole code, so problem may be elsewhere).

 

Without a way to reproduce the problem I can't really help you.

Link to post
Share on other sites

Okay i changed it to use the thread counter read instead of by variable and its still miscounting. I changed my thread code to be exactly like your example as well with the only difference being my define command. the thread counts are all outside of my define so nothing within the define code should be messing up the thread counter....

Link to post
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.

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.

Loading...

×
×
  • Create New...