简体   繁体   English

从C#向Python发送长字符串的最快方法

[英]Fastest way to send long string from C# to Python

I have a long string of data streaming continuously, which is generated by my C# script. 我的C#脚本会生成一长串连续不断的数据流。 I would like to use it as an input to Python Machine Learning model. 我想将其用作Python机器学习模型的输入。

What is the fastest & easiest way to implement this transmission? 最快最简单的传输方式是什么?

I have found some possible options: 我发现了一些可能的选择:

  1. Use sockets. 使用插座。
  2. Use http. 使用http。
  3. Write data to a file from C#, and read the file from Python 从C#将数据写入文件,然后从Python读取文件
  4. Data as an argument, while python is running as a process in C# or 数据作为参数,而python作为C#或进程运行

  5. Something different? 有些不同?

Provided that these processes run on the same machine, I think when handling big chunks of data between process memory mapping is the way to go. 只要这些进程在同一台机器上运行,我认为在进程内存映射之间处理大数据块时是必须走的路。

In other case TCP/UDP sockets is a good option since they don't have the overhead of the Application layer which, HTTP for example, has 在其他情况下,TCP / UDP套接字是一个不错的选择,因为它们没有应用层的开销,例如HTTP

I suggest option 6 Use Database like sqlite. 我建议选项6使用像sqlite这样的数据库。

With this option you gain: 使用此选项,您可以获得:

  • Both running OnLine 两者都在线运行
  • Python set flags to these records in database when they processed. Python处理这些记录时,会为数据库中的这些记录设置标志。
  • You can complete operation latter if python off, and continue processing data. 如果python关闭,则可以在后面完成操作,然后继续处理数据。
  • You can add results from python to the database. 您可以将python的结果添加到数据库中。
  • you have a history in database you may need latter for post processing. 您在数据库中有一个历史记录,可能需要后者进行后期处理。

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

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