Untitled
unknown
plain_text
3 years ago
657 B
9
Indexable
// Start the Python runtime
PythonEngine.Initialize();
// Create 4 tasks, each with their own Python interpreter
var tasks = new Task[4];
for (int i = 0; i < tasks.Length; i++)
{
tasks[i] = Task.Run(() =>
{
using (Py.GIL())
{
dynamic math = Py.Import("math");
Console.WriteLine($"Thread {i + 1}: {math.pi}");
}
});
}
// Wait for all tasks to complete
Task.WaitAll(tasks);
// Shut down the Python runtime
PythonEngine.Shutdown();Editor is loading...