some comments on python and multi-core

since my first time to dabble at python, i began to keep an eye on its performance in multi-core enviornment. As everyone knows, python adapt GIL to prevent thread from interrupting the data.

the pros is learning and using thread become easy and error-less, the downside is you are unable to take any benefit from using multi-core/cpu. A few years ago, i thought probably the next generation of python (next generation of python refers to python 3000 in context) may remove this bar. However, it is not true.

 

There are few ways of bypassing the GIL and taking benefit from multi-core, after years study and search, i conclude some ways which are listed as follow:

 

1. use OS-related API to write your code where you need multi-thread, and wrap it as module. the downside is the development speed is slowly and error-prone. using os api let cross-platform become more difficult.

 

2. use multi-process instead of multi-thread. If you live in Linux, you will be fine with this choice. The python provide os.fork for multi-process usage, furthmore, you may also use a package called pyprocessing. The usage is similar with threading package. The author claims that the package can be used in both of *nix and win32. However, after a few days of use in win32,  i found out that it probably was not a feasible choice. The restrictions of pyprocess in win32 are more tense than Linux, the argument, shared object, or data put in a Queue should be pickable (io serialization), that imply some un-plain objects like com-object, proxy-object can not be passed or communicate interprocess. It quickly become a harassment. I personally don't recommend use this package in production development.

 

3. it is said that use twisted and prospective broker can take benefit from multi-core, however, i havent' gave it a try. I found someone reported that the use of multi-core in twisted is boloney.

If your app is related to server, it is not a bad choice

 

4. the final choice is to use jython or ironPython instead, these versions of python are based on VM/CLR which supports multi-thread naturally.

 

Python-someip-automotive是一个用于实现SomeIP(Scalable Service-Oriented MiddlewarE over IP)通信的Python库。SomeIP是一种用于在汽车电子系统中进行通信的协议,它允许不同的ECU(Electronic Control Unit)之间进行消息交换。 要使用python-someip-automotive实现SomeIP通信,可以按照以下步骤进行: 1. 安装python-someip-automotive库:可以使用pip命令来安装该库,如下所示: ``` pip install python-someip-automotive ``` 2. 导入所需的模块:在Python脚本中,需要导入python-someip-automotive库的相关模块,如下所示: ```python from someip import SomeIPClient, SomeIPServer, SomeIPMessage ``` 3. 创建SomeIP客户端或服务器对象:根据需要,可以创建SomeIP客户端或服务器对象。客户端用于发送SomeIP消息,服务器用于接收SomeIP消息。例如,创建一个SomeIP客户端对象: ```python client = SomeIPClient() ``` 4. 配置SomeIP客户端或服务器:可以通过设置相关参数来配置SomeIP客户端或服务器。例如,设置SomeIP客户端的服务ID和方法ID: ```python client.service_id = 0x1234 client.method_id = 0x5678 ``` 5. 发送SomeIP消息(客户端)或处理SomeIP消息(服务器):根据是客户端还是服务器,可以发送SomeIP消息或处理接收到的SomeIP消息。例如,发送SomeIP消息: ```python message = SomeIPMessage() message.set_payload(b'Hello, SomeIP!') client.send_message(message) ``` 以上是使用python-someip-automotive库实现SomeIP通信的基本步骤。你可以根据具体的需求和场景进行进一步的配置和操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值