有没有一种方法可以实现非阻塞/异步执行(无需 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中有任何方法可以实现多任务处理(并行,非阻塞,异步执行代码)而无需 fork() 'ing-类似于Python中的 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中的非阻塞/异步执行
发布评论