What is multi-threading
As we have discussed above that, threads run on same memory location so similarly multiple threads are also live/run on same memory spaces (heap memory). Each thread performs its own specific task.Why we use multi-threading in odoo?
For example we want to insert huge amount of data in database table or we want to perform some huge calculations for all records on button click, in odoo that takes to much time, to improve this process we need multi-threading.Below are the steps to perform multi-threading in odoo on button click.Use Multi Threading to Seed Up Processing in Odoo
1- Import python libraries for multi-threading
2- Create a function that will convert our record ids into the multi dimensional arrays/list. For example if we have 30 records than this function will convert these records into the 10 arrays, and each array has 3 elements. In simple words we will split our data and assign that data in a variable.
Output:
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21], [22, 23, 24], [25, 26, 27], [28, 29, 30]]
3- In next step we will use that variable as an argument to call python multi thread. Remember the number of thread will be same as the number of variable as we have created in step number 1.
4- In each thread we have a function named "_run_process", this function will create a new env (environment) for us to perform processes in multi-threading. For the rest of the code we will use this newly created environment to perform process in batch or multi-threading mode.
2 Comments
i called function from _run_process function, every self crash after that .
ReplyDeletehow can i manage it?
can you please share your error log
Delete