Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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; } } }

In reply to RSperl & threads by sperlyjinx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-28 19:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found