简体   繁体   English

如何在实时优先级Linux上运行Python程序

[英]How to run Python program with realtime priority Linux

I am writing a python program that is latency sensitive (taking stereo images simultanously from 2 cameras). 我正在编写一个对延迟敏感的python程序(从2个摄像机同时拍摄立体图像)。

I am reading up on real time operating systems and I would like to run my python program with SCHED_FIFO or FF priority or something similar. 我正在阅读实时操作系统,我想以SCHED_FIFO或FF优先级或类似的方式运行我的python程序。 I am using Rasbian(debian) with RT_PREMPT kernal. 我正在使用带有RT_PREMPT内核的Rasbian(debian)。

Is this the right approach? 这是正确的方法吗? How do I run my python program with real time (SCHED_FIFO) priority? 如何以实时(SCHED_FIFO)优先级运行python程序?

attempt 尝试

sudo chrt --rr 50 python3 loopExample.py 须藤chrt --rr 50 python3 loopExample.py

In order to do true realtime operations, you might want to consider running a realtime Linux kernel. 为了进行真正的实时操作,您可能需要考虑运行实时Linux内核。 It can make a dramatic difference in terms of max latency and give you a more consistent response time, as you can see from this benchmark test on the Pi 正如在Pi上进行的基准测试所看到的,它可以在最大延迟方面产生巨大的变化,并为您提供更一致的响应时间

You can get the Raspberry PI's version of the RealTime kernel here . 您可以在此处获得Raspberry PI的RealTime内核版本。 You will need to compile and install it, this should help get you there . 您将需要编译并安装它, 这应该有助于您到达那里

In terms of updating a process' priority under Linux, this is called the "nice" value. 就在Linux下更新进程的优先级而言,这称为“ nice”值。 The range of values available is between -20 for highest priority and 19 for lowest. 可用值的范围在-20(最高优先级)和19(最低优先级)之间。 You can run your Python application with a set nice value at the time of invocation using sudo nice -n -20 python app.py 您可以在调用时使用sudo nice -n -20 python app.py以设定好的值运行Python应用程序

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

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