In this video I am going to show you the exact process I take to do multithreading in Ubot Studio.
I have used this technique in hundreds of bots, including the account creator we are going to make today.
I see people asking on Ubot forums all the time about multi threading and using Thread Spawn, and so I wanted to make a video showing you the right way to do multi threading in Ubot Studio.
The truth is that you don’t need thread spawn in order to do multithreading and doing it the right way gives you more control over the process. More control is better because it can lead to less errors and headaches later on. I know multithreading can be scary to some but I will break it down and show you that it’s pretty straight-forward and easy to do.
So let’s jump right in and learn the exact process I use.
Today we will be making an account creator for a form on the Ubot Playground.
First of all I am going to get rid of all this code so that we can make this together step-by-step.
Before we begin we need to list our requirements for this project:
- We need to make an account creator for the simple form on Ubot playground.
- This account creator should be able to be ran multi-threaded
- We should be able to control the thread count, it should not be fixed
- Accept a number of accounts to create
- Use random account information for the username and password fields
- First name, last name, and about me fields are spun text
- Save the username and password to a list
As you can see we have a number of specific requirements that should be met for this project.
So let’s get started.
The first thing I always want to do when creating a multi-threaded program is to make the core part of the program, and test that to ensure that it works before adding any multi-threaded logic.
Once the program is multithreaded you don’t want to do any major debugging. In fact the only debugging you should be doing at that point should be related to the multithreading logic itself, and not the core of your program. If you find any problems with the core of your script then copy it out from the multi-threaded environment so that you can properly debug it.
With that in mind let’s make the core part of the program, and in this case it’s pretty simple, we need to go to a webpage and fill in a form.
Recall that requirements 5 and 6 have to do with the information to be filled in. Requirement 5 states that we should “Use random account information for the username and password fields” and 6 says “First name, last name, and about me fields are spun text.” We can take care of that part now, and then later modify it for multi-threading.
Our last requirement says that we need to save the username and password combination to a list, we can also do that now.
Now we have the core of the application, the part that is doing the actual work. So now we should run this a couple of times to be sure we get the expected results.
In the real world your application would be much more complex than this. You would want to have built in logic to solve problems such as:
- Info already taken such as username, or email
- Invalid passwords
- Failed captchas
- And more
For now we want to keep it as simple as possible just to demonstrate how multi-threading works, so with that in mind we won’t be doing any more than this.
So let’s run it a couple of times and make sure it does everything we expect.
Now we can fulfill requirement number 4 which was to accept the number of accounts to create. This is simply just going to be the number of times we loop.
Because I know that we are going to multi-thread this I am going to save some time and put the main process in it’s own custom command. For more complex programs you may already have done this, and you should be doing this if you are not yet.
Now I can just drop the custom command into a loop and add the user input.
We can give this another test to ensure we still don’t have any problems.
Now that we have the core of our program we can now work on the multithreading part. Multithreading scares a lot of people because they think that it’s complicated. But I don’t want you to think about it that way. Remember that at this point we have already made the core of the program and we know that it works. Now all that is left is creating a little bit of code to manage how many threads can run at once.
To accomplish this we only need a few simple things:
- We need to know how many threads can run at once
- We need to limit the application so that it does not exceed that number
- And finally, we need to know when a thread starts and ends
And that is really all there is to it. When you break down multithreading it’s not really all that complicated. Our job is to make sure that no more than a certain number of threads are running at the same time. And to do that we only need to use a little bit of code.
Now the first thing we need to do is make sure that we know how many threads the user wants and to accomplish this task we can use a dropdown. We use a drop down here because that way we can control the input. Not only are we limiting the input only to numbers but we can also specify a minimum and maximum thread count.
Now that we know the thread count our job is to simply ensure that the number of open threads does not exceed that number.
So let’s first ensure that the part we want to be multithreaded – is in a thread.
We need to keep track of the open threads so that we don’t exceed the max thread count. To do this we can simply use a variable.
So far we already know how many threads to run and we already know when a thread begins and ends. Believe it or not were already almost done, now all we really need to do is limit how many threads are open at once and we can do that using a loop while.
So you are going to want to put this above the increment.
This loop while is the heart of the multithreaded code, it controls how many threads are open at one time.
Now that is basically it, however, there is a few extra bits we need to add to really make this work well in all situations.
The first is really important, we need to put a small wait after we create a new thread. This is going to make sure everything runs smoothly and will essentially eliminate any errors that you would normally see while multithreading.
And finally, once our main loop is finished we will likely still have open threads. So typically you want to wait until all threads are finished before letting your program continue.
To do this we simply put a loop while after the loop which contains your multithreaded logic.
And that’s all there is to it. Now our application will allow the user to specify the number of threads and the program will not exceed that number. When the main loop is finished the program will wait for all threads to finish as well before continuing.
And now that our program is multithreaded we can give it a shot.
At this point we have fulfilled our 7 requirements. We have made an account creator and then multi-threaded it. The program accepts a number of accounts to create as well as the thread count. We are using random account information and save off the username and password to a list.
The multithreading part was achieved simply by accepting a maximum thread count and then managing it with a loop while. We kept track of when threads open and close simply by incrementing and decrementing a variable. And when our main loop was finished we waited for all threads to finish before allowing our script to continue.
I hope you can see that multithreading is fairly straight forward and easy to implement. If you liked this video please feel free to like and subscribe and don’t forget to check out Elite Botters.com as well.
That’s going to do it for me for this one. If you have any questions leave them in the comments section below and I’ll see you in the next video.