in reply to Net::SSH2 issue in thread

I would avoid mixing threads and C libraries (in this case, Net::SSH2). Most likely, the C library is not really thread-safe and will only ever work from within one thread.

You don't show how you start up threads and how your threads use the object and the function sftp_file. Maybe only ever using sftp_file from one thread might work, but that's hard to say without seeing the code you're actually using.

Replies are listed 'Best First'.
Re^2: Net::SSH2 issue in thread
by roperl (Beadle) on Jul 31, 2018 at 16:39 UTC
    According to the libssh2.org site, it is thread safe: "Thread-safe: just don't share handles simultaneously"

    I'm not sure if I am sharing handles simultaneously

    At the top of my code I call
    use Net::SSH2;
    Then I create my threads
    my $work_q = Thread::Queue->new(); my $thr = threads->new( 'file_worker', $work_q );
    In my file_work sub I call the sftp_file if the file is found and supply the required arguments
    my $retval = sftp_file($file,$destfile,$host,$port,$user,$privpath,$pu +bpath,$pass);