Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
713 B
0
Indexable
Never
// 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())
                {
                    PyObject result = PythonEngine.RunString("def hello():\n  return 'Python yes' + str(55)\n\nhello()");
                    Console.WriteLine(result.ToString());
                }
            });
        }

        // Wait for all tasks to complete
        Task.WaitAll(tasks);

        // Shut down the Python runtime
        PythonEngine.Shutdown();