Perl中的非阻塞/异步执行 [英] Non-blocking / Asynchronous Execution in Perl

查看:232
本文介绍了Perl中的非阻塞/异步执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以实现非阻塞/异步执行(无需 fork() 'ing) Perl?

Is there a way to implement non-blocking / asynchronous execution (without fork()'ing) in Perl?

我曾经是一名Python开发人员很多年... Python具有非常强大的"Twisted"框架,可以做到这一点(使用 POE框架-似乎与我要搜索的内容足够接近".但是...在花了一些时间阅读文档并玩"了代码之后,我碰到了墙"-这是有局限性的(摘自 POE :: Session 文档):

I used to be a Python developer for many years... Python has really great 'Twisted' framework that allows to do so (using DEFERREDs. When I ran search to see if there is anything in Perl to do the same, I came across POE framework - which seemed "close" enough to what I was searching for. But... after spending some time reading the documentation and "playing" with the code, I came against "the wall" - which is following limitation (from POE::Session documentation):

回调不是抢占式的.只要一个正在运行,就不会派遣其他任何人.这称为协作多任务处理.每个会话必须通过返回中央调度内核来进行协作.

Callbacks are not preemptive. As long as one is running, no others will be dispatched. This is known as cooperative multitasking. Each session must cooperate by returning to the central dispatching kernel.

通过限制在任何给定时刻仅执行一个回调(代码块),此限制实质上破坏了异步/并行/非阻塞执行的目的.当其他回调已经在运行时,其他任何回调都无法开始运行!

This limitation essentially defeats the purpose of asynchronous/parallel/non-blocking execution - by restricting to only one callback (block of code) executing at any given moment. No other callback can start running while another is already running!

所以... Perl中有任何方法可以实现多任务处理(并行,非阻塞,异步执行代码)而无需 DEFERREDs ? /p>

So... is there any way in Perl to implement multi-tasking (parallel, non-blocking, asynchronous execution of code) without fork()'ing - similar to DEFERREDs in Python?

推荐答案

Coro 是POE和线程之间的混合.通过阅读其CPAN文档,我认为IO :: Async可以进行真正的异步执行. 线程也可以使用-至少Padre IDE成功使用了它们.

Coro is a mix between POE and threads. From reading its CPAN documentation, I think that IO::Async does real asynchronous execution. threads can be used too - at least Padre IDE successfully uses them.

这篇关于Perl中的非阻塞/异步执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆