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; }
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.