Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Perl detached threads, loops & my?

by expresspotato (Beadle)
on Jun 09, 2010 at 01:56 UTC ( #843786=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl detached threads, loops & my?
in thread Perl detached threads, loops & my?

@BrowserUK - I am using the latest version of perl (why would anyone use anything less?)
The only reason I "store them" is to ensure it is a fresh thread everytime. Using my $thr -> will eventually crash.
The script is designed to do one thing. Process the list of tasks and just keep on going. Tasks (detached threads) may take a second and they may take an hour.
I do not claim it takes "Hours to run", I claim it may be "run for hours".
@llancet
Ah ha! See... Always calling my $thr on occasion seems to overwrite / invalidate the older thread. When checking memory usage using my $thr, it never seems to increase which is very odd to me.
@rjt
Thanks for the code, however the script is "always running" and does not ever exit.
Perhaps the actual code will shed some light on what is really going on. Its attached below. Keep in mind the same problem still exists. How to ensure this is a FRESH thread (as my or the same $thr will eventually crash), without wasting all that memory.

use threads; do("./sql.pl"); #NOT INCLUDED IN EXAMPLE $thr4 = threads->new(\&processor); $thr4->detach(); sub processor{ my $select; $select = qq~ select * from pool_process where any="1" and status +="" order by id asc limit 1; ~; while (1){ if ($sys_ok == 1){ sleep(1); my @row = &row_sql($select,-1); if (!(@row)){ #pass }else{ &del_sql(qq~ update pool_process set status = "RUNNING",proc +_srv="$server_id" where id="@row[0]"; ~,-1); print "Processing (@row[1],@row[2],@row[3],@row[4])\n"; $used_threads++; my $thr =threads->new(\&process_start,@row[1],@row[2],@row[3 +],@row[4],@row[5],@row[6],@row[7],@row[0]); $thr->detach(); if (@row[4] eq "generate_details"){ sleep(3); } } }else{ sleep(30); } } } sub process_start{ my $return_code = system(qq~ perl ./thread_process.pl "$_[0]" "$_[ +1]" "$_[2]" "$_[3]" "$_[4]" ~); }


Comment on Re^2: Perl detached threads, loops & my?
Download Code
Re^3: Perl detached threads, loops & my?
by BrowserUk (Pope) on Jun 09, 2010 at 02:23 UTC

    @expresspotato. This ain't twitter.

    What you are doing makes no sense.

    What you say you need: "FRESH threads" makes no sense.

    And if you cannot be bothered to answer my questions properly, then I can't be bothered to help.

    Good luck.

Re^3: Perl detached threads, loops & my?
by rjt (Deacon) on Jun 09, 2010 at 03:08 UTC

    This is obviously neither the real code nor an example that we can run. Please, help us help you. Read the responses you've been given, and give us a minimal and runnable! example (with inputs and expected outputs) with strict and warnings that we can use to reproduce the undesired behavior that you see. Until then, we can't effectively help you.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://843786]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-12-18 03:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls