简体   繁体   English

Python.Net C# 使用线程调用 python function

[英]Python.Net C# using thread to call python function

I am currently working with C# and Python through PythonNet.我目前正在通过 PythonNet 使用 C# 和 Python。 It works well calling and using python functions from C#. However, the problem is when I tried to call python function in async condition by using multi-thread.它可以很好地调用和使用 C# 中的 python 函数。但是,问题是当我尝试使用多线程在异步条件下调用 python function 时。 As I googled so far, I found some issues that python has "GIL" so that it blocks multi-threading.到目前为止,我在谷歌上搜索时发现了一些问题,即 python 具有“GIL”,因此它会阻止多线程。 Even that case, I can still call python function in async and use it if it was written in Built-in functions only in python, which means, it is not possible to use other library functions in python.即使那样,我仍然可以异步调用 python function 并使用它,如果它仅在 python 中的内置函数中编写,这意味着,不可能在 python 中使用其他库函数。

My questions,我的问题,

  1. is there any other way to use mulit-threading in pythonNet有没有其他方法可以在 pythonNet 中使用多线程
  2. why I can't import libraries in python when I tried in async为什么我尝试异步时无法导入 python 中的库

According to pyhto.net documentation根据 pyhto.net 文档

  • If you plan to use Python objects from multiple threads, also call如果您计划使用来自多个线程的 Python 个对象,也可以调用
PythonEngine.BeginAllowThreads()

Source: https://github.com/pytho.net/pytho.net来源: https://github.com/pytho.net/pytho.net

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM