Is LWP::UserAgent not thread-safe?

后端 未结 1 1881
[愿得一人]
[愿得一人] 2021-01-22 07:37

I\'m running 40-or-so threads with the following subroutine:

my $app = shift;
my $ua = LWP::UserAgent->new();
$ua->timeout(5);
my $response = $ua->get($         


        
相关标签:
1条回答
  • 2021-01-22 07:58

    Non-thread safe pure-Perl code does not cause a segfault (in fact, no pure Perl code should cause a segfault). A bug in Perl causes a segfault. And threads in Perl are historically very buggy, but they've gotten a lot better.

    Your code runs fine in 5.10.1, and HTTP::Lite probably just doesn't tickle whatever perl bug you've run into. Likely you just need to use a newer version of Perl. The older and closer to Redhat you get, the less stable threads are. If you're going to use threads, use the newest Perl you can get your hands on.

    As an alternative to threads, you can use something like Parallel::ForkManager, LWP::Parallel or even the amazing forks module which emulates threads using fork.

    0 讨论(0)
提交回复
热议问题