如何在 Perl 中安排任务?
有谁知道 perl 是否支持任务调度程序?
我正在开发控制一堆 perl 脚本的 ac# 程序。珀尔 脚本通过套接字接口与某些设备通信。设备“目标” ,是一种需要实时交互的嵌入式系统设备。
我需要满足的要求之一是当我收到消息“A”时 我需要从设备安排一个将在 15 毫秒内发生的事件 将来。此事件将向 UT 发送消息。我们这里称之为“B”。 延迟功能在这里不起作用,因为其他消息不应该被阻止,因为 消息“B”。有时,我还需要每 15 毫秒发送一次消息“B”。
或者也许 Perl 在这里不是一个好的选择。
谢谢
Does anyone knows if perl supports a task scheduler?
I am working on a c# program that controls a bunch of perl scripts. The perl
script talked to some device over the socket interface. The device, "target"
, is a embedded system device that require real time interaction.
One of the requirements I need to fulfill is that when I receive message "A"
from the device, I need to schedule an event that is going to happen in 15 miliseconds
in the future. This event is going to send the message to UT. We call it "B" here.
The delay function wouldn't work here because other messages shouldn't be blocked because
of Message "B". Sometimes, I also need to send Message "B" every 15 miliseconds.
or Maybe Perl is not a good choice here.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种事件驱动的非阻塞框架可用于 Perl。他们中的任何一个都应该能够满足您的需求。以下是帮助您入门的三个示例:POE、AnyEvent 和 IO::异步。也就是说,如果您的时间限制很严格(“每次 15 毫秒”),那么使用 C 等较低级语言编写的实时调度程序可能更合适。
There are several event-driven non-blocking frameworks available for Perl. Any one of them should be able to do what you need. Here are three examples to get you started: POE, AnyEvent, and IO::Async. That said, if you timing constraints are rigorous ("15 milliseconds on the nose, every time"), then a real-time-scheduled program in a lower-level language like C is probably more appropriate.
使用正确的工具做正确的事。我强烈建议您不要使用 Perl 来完成此类任务。例如,如果您使用 Erlang 来完成此任务,您只需在纯 Erlang 中执行此操作(只是语言核心,而不是任何模块/库):
或者使用计时器模块,
这比在 Perl 中实现的更可靠、更简单。这是我在 Perl 日常专业开发七年后可以向您推荐的内容。
Use right tool for right thing. I would strongly recommend you to don't use Perl for this sort of tasks. If you use for example Erlang for this task you will just do this in pure Erlang (just language core, not any module/library):
or using timer module
It is magnitude more reliable and simpler what you can achieve in Perl. It's what I can recommend you after seven years daily professional developing in Perl.