Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Cannot Remove Redefined Warnings

by Sukhster (Sexton)
on May 05, 2025 at 20:39 UTC ( [id://11164953]=note: print w/replies, xml ) Need Help??


in reply to Cannot Remove Redefined Warnings

Investigation continues. The issue is running the subroutine in separate threads. And when l wrote this some years ago, l put a comment about the following code.

It looks like this code no longer works, i.e. the refined warnings continue. It is the connect_to_database code that is triggering the redefin warnings.

I removed use warnings altogether, replaced the code below with no warnings in different varieties - but CANNOT remove the redefined warnings.

Any suggestions? I need each thread to hold a separate connection to the database.

###################################################################### +######### # Function: connect_to_database # Purpose: Connect to the Oracle database # Arguments: $db_uid, $db_pwd, $db_sid # Returns: $dbh ###################################################################### +######### sub connect_to_database($$$) { # Declare the variables my ($db_uid, $db_pwd, $db_sid) = @_; my $dbh; my %attribs = ( PrintError => 0, AutoCommit => 0, RaiseError => 0 ); $dbh = DBI->connect("DBI:Oracle:".$db_sid, $db_uid, $db_pwd , +\%attribs ) or die "ERROR: Can't connect to database ($db_uid\@$d +b_sid): ".$DBI::errstr."\n"; return $dbh; } ..... # Remove erroneous "subroutine redefined" warning { BEGIN { $^W = 0 } $dbh = connect_to_database($db_uid, $db_pwd, $db_sid); }

Replies are listed 'Best First'.
Re^2: Cannot Remove Redefined Warnings
by Corion (Patriarch) on May 06, 2025 at 07:20 UTC

    Ideally, you only ever use a single thread to connect to Oracle, as many C libraries (and that includes database drivers) are not thread-safe.

    If you really want to use multiple threads to connect to Oracle simultaneously, you need to make sure that every thread initializes its own, separate database connection.

    It might be that you already are doing this and that connect_to_database (resp. the code in DBI) installs new subroutines. Then another approach could be to connect to the database once, before spawning any thread, and close that connection again. This could make the Perl setup happen. Closing the database handle again means that your other threads will not stomp on each other, reusing the master connection.

Re^2: Cannot Remove Redefined Warnings
by NERDVANA (Priest) on May 06, 2025 at 00:05 UTC
    A threading problem makes sense. Threading doesn't get nearly as much community testing because people usually use process-level workers. What if you make sure DBD::Oracle is loaded by the main thread prior to forking?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2026-03-10 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.