Which is equivalent to setting c # in python

I need to translate my C # code to python. I have a task in C # and I need to translate it into python. Here is the code snippet:

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 small piece of code is critical to running my program. I need python to run all the tasks in the list in separate threads and block the main thread until all tasks are complete. Does this function have python?

+6
source share
2 answers

I need Python to run all the tasks in the list and then block the main thread until all tasks are complete.

The main use case for Task is to avoid blocking the main thread, so the user can interact with the application while the work is being transferred to different threads.

Are you just trying to implement parallelism between separate jobs?
If you are using Python 3.2, there is concurrent.futures that looks like a TPL in some way.

+1
source

A task is simply an operation performed as its own thread. Just create a thread and let it do something specific, and you have your task.

0
source

Source: https://habr.com/ru/post/946628/


All Articles