I need to translate my c# code to python. I have a Task in c# and need to translate it to python. Here is a piece of the code:
List<Task> t = new List<Task>();
for(int i = 0; i < _tasks.Count; i++)
{
var theTask = _tasks[i];
t.Add(Task.Factory.StartNew(() => theTask.SAPTask.Execute(theTask.index, theTask.WindowCount)));
}
t.ForEach(x => x.Wait());
This little piece of code is crucial to run my program. I need python to run all the tasks in the list in separate threads, and block the main thread until all the tasks are completed. Does python have this functionality?
The closest thing you can get is a struct .
C++ was developed by Bjarne Stroustrup in 1979. C does no support polymorphism, encapsulation, and inheritance which means that C does not support object oriented programming. C++ supports polymorphism, encapsulation, and inheritance because it is an object oriented programming language. C is (mostly) a subset of C++.
P→Q is logically equivalent to ⌝P∨Q. So. ⌝(P→Q) is logically equivalent to ⌝(⌝P∨Q).
The best alternative is Java. It's not free, so if you're looking for a free alternative, you could try C++ or Rust. Other great apps like C (programming language) are Go (Programming Language), C#, Lua and Perl.
I need Python to run all the tasks in the list and then block the main thread until all the tasks are completed.
The main use case for Task
is to avoid blocking the main thread, so the user can interact with application while the work is pushed to different threads.
Are you just trying to implement parallelism between individual pieces of work?
If you're using Python 3.2, there is concurrent.futures
that does look like TPL in a way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With