Home > Archive > PERL POE > February 2006 > threads and poe?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Whitney Jackson 2006-02-25, 7:02 pm |
| >From the FAQ:
"POE currently is not thread-safe, in that you can't run entire sessions
within subthreads.
POE is very flexible, however. It may be possible to spawn threads for
dedicated tasks, and pass information back and forth using
Thread::Queue. To our knowledge, nobody has done this yet."
I'm doing exactly this and so far it seems to work just fine. The only
problem I've had is that subthreads don't use file descriptors 0, 1, and
2 for STDIN, STDOUT, and STDERR. So when using POE::Wheel::Run I have
to change this:
my $program = '/bin/bla';
my $wheel = POE::Wheel::Run->new(
program => $program,
...
);
to:
my $stdin_fn = fileno(STDIN);
my $stdout_fn = fileno(STDOUT);
my $stderr_fn = fileno(STDERR);
my $program = "/bin/bla 0<&$stdin 1>&$stdout 2>&stderr";
my $wheel = POE::Wheel::Run->new(
program => $program,
...
);
Am I asking for trouble running POE Sessions inside of threads? What
other problems might i run into? Am I really the first person to try
this?
Whitney
| |
| Artur Bergman 2006-02-27, 7:21 pm |
|
On 25 Feb 2006, at 15:35, Whitney Jackson wrote:
>
> "POE currently is not thread-safe, in that you can't run entire
> sessions
> within subthreads.
>
> POE is very flexible, however. It may be possible to spawn threads for
> dedicated tasks, and pass information back and forth using
> Thread::Queue. To our knowledge, nobody has done this yet."
>
> I'm doing exactly this and so far it seems to work just fine. The
> only
> problem I've had is that subthreads don't use file descriptors 0,
> 1, and
> 2 for STDIN, STDOUT, and STDERR. So when using POE::Wheel::Run I have
> to change this:
>
> my $program = '/bin/bla';
> my $wheel = POE::Wheel::Run->new(
> program => $program,
> ...
> );
>
> to:
>
> my $stdin_fn = fileno(STDIN);
> my $stdout_fn = fileno(STDOUT);
> my $stderr_fn = fileno(STDERR);
> my $program = "/bin/bla 0<&$stdin 1>&$stdout 2>&stderr";
>
> my $wheel = POE::Wheel::Run->new(
> program => $program,
> ...
> );
>
> Am I asking for trouble running POE Sessions inside of threads? What
> other problems might i run into? Am I really the first person to try
> this?
>
> Whitney
>
I have tried this, and it kind of works, the problems I found was in
shutdown of a thread, it would run destructors for all of POE and
thus close filehandles and do other bad things that existed before
the thread got started.
I wrote a patch a long time ago that let you specify thread => 1, as
an option to a session and it would run in a different thread. But
because of the memory bloat I found very little practical use.
Artur
| |
| Artur Bergman 2006-02-27, 7:21 pm |
|
On 25 Feb 2006, at 15:35, Whitney Jackson wrote:
>
> "POE currently is not thread-safe, in that you can't run entire
> sessions
> within subthreads.
>
> POE is very flexible, however. It may be possible to spawn threads for
> dedicated tasks, and pass information back and forth using
> Thread::Queue. To our knowledge, nobody has done this yet."
>
> I'm doing exactly this and so far it seems to work just fine. The
> only
> problem I've had is that subthreads don't use file descriptors 0,
> 1, and
> 2 for STDIN, STDOUT, and STDERR. So when using POE::Wheel::Run I have
> to change this:
>
> my $program = '/bin/bla';
> my $wheel = POE::Wheel::Run->new(
> program => $program,
> ...
> );
>
> to:
>
> my $stdin_fn = fileno(STDIN);
> my $stdout_fn = fileno(STDOUT);
> my $stderr_fn = fileno(STDERR);
> my $program = "/bin/bla 0<&$stdin 1>&$stdout 2>&stderr";
>
> my $wheel = POE::Wheel::Run->new(
> program => $program,
> ...
> );
>
> Am I asking for trouble running POE Sessions inside of threads? What
> other problems might i run into? Am I really the first person to try
> this?
>
> Whitney
>
I have tried this, and it kind of works, the problems I found was in
shutdown of a thread, it would run destructors for all of POE and
thus close filehandles and do other bad things that existed before
the thread got started.
I wrote a patch a long time ago that let you specify thread => 1, as
an option to a session and it would run in a different thread. But
because of the memory bloat I found very little practical use.
Artur
|
|
|
|
|