sperlyjinx has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I'm trying to use the RSPerl module in a script that uses threads. I am able to call R functions without a problem when I don't use threads. However, using threads, I get varying errors depending on how I call the R functions. If I call the R::initR function in the "boss" thread and then try to call R functions from a "worker" thread, I get the following error:
Error: C stack usage is too close to the limit
Caught error in R::call()
However, if I move the "use" declarations for R & RReferences to the worker thread, along with the initR call, I get this:
Fatal error: R home directory is not defined
I've attached some code for your reference. Is there any way to get this module working with Perl threads? Thanks in advance for your help.
-Jay
#!/usr/bin/perl use warnings; use strict; #use R; #use RReferences; #&R::initR("--silent"); use threads; use threads::shared; use Thread::Queue; our $queue : shared = Thread::Queue->new; our $hold : shared; my $thr = threads->new (\&command_runner); $hold =1; $queue->enqueue("ls"); while ($hold) { sleep(1); } $queue->enqueue("end"); $thr->join(); # Thread for processing functions sub command_runner { use R; use RReferences; &R::initR("--silent"); my $run = 1; # run until return while ($run) { # This call will block until the main thread sends the job my $job = $queue->dequeue; print "j: $job\n"; if ($job eq "ls"){ R::ls(); } elsif ($job eq "end") { $run = 0 } { lock $hold; $hold = 0; } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: RSperl & threads
by renodino (Curate) on Apr 08, 2008 at 19:50 UTC | |
Re: RSperl & threads
by zentara (Archbishop) on Apr 08, 2008 at 21:26 UTC | |
Re: RSperl & threads
by zentara (Archbishop) on Apr 10, 2008 at 13:53 UTC | |
by sperlyjinx (Initiate) on Apr 14, 2008 at 04:09 UTC | |
by Anonymous Monk on Apr 23, 2008 at 23:29 UTC | |
by Anonymous Monk on Jul 12, 2008 at 15:23 UTC | |
by lsm (Initiate) on Jul 12, 2008 at 15:27 UTC | |
by amesdaq (Initiate) on Oct 21, 2010 at 18:56 UTC |
Back to
Seekers of Perl Wisdom