如何在 Perl 中安排任务?

发布于 2024-08-13 18:20:01 字数 296 浏览 7 评论 0原文

有谁知道 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉鱼一梦 2024-08-20 18:20:01

有多种事件驱动的非阻塞框架可用于 Perl。他们中的任何一个都应该能够满足您的需求。以下是帮助您入门的三个示例:POEAnyEventIO::异步。也就是说,如果您的时间限制很严格(“每次 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.

奶茶白久 2024-08-20 18:20:01

使用正确的工具做正确的事。我强烈建议您不要使用 Perl 来完成此类任务。例如,如果您使用 Erlang 来完成此任务,您只需在纯 Erlang 中执行此操作(只是语言核心,而不是任何模块/库):

receive
  {Device, "A"} -> spawn(fun() -> send_interval(15, UT, "B") end)
end

send_interval(Interval, Dest, Msg) ->
  receive after Interval ->
      send_interval(Interval, Dest, Dest ! Msg)
  end.

或者使用计时器模块,

receive
  {Device, "A"} -> timer:send_interval(15, UT, "B")
end

这比在 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):

receive
  {Device, "A"} -> spawn(fun() -> send_interval(15, UT, "B") end)
end

send_interval(Interval, Dest, Msg) ->
  receive after Interval ->
      send_interval(Interval, Dest, Dest ! Msg)
  end.

or using timer module

receive
  {Device, "A"} -> timer:send_interval(15, UT, "B")
end

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文