in reply to HTTP Request and Threads
The first thread would run fine. But the second thread would always cause a crash
I've tried running your code as-is and cannot get it to crash (over the space of a few runs) on my perl which is This is perl 5, version 20, subversion 3 (v5.20.3) built for x86_64-linux-thread-multi. To remove some possible sources of error I then made a few changes and come up with this, which I can't get to crash either.
#!/usr/bin/perl -l use strict; use warnings FATAL => 'all'; use threads; use threads::shared; use HTTP::Headers; use LWP::UserAgent; my $counter_thread : shared; sub getgoog { my $method = "GET"; my $uri = "https://www.google.com/"; my $header = HTTP::Headers->new(); $header->push_header("Content-Type" => "application/json"); my $ua = LWP::UserAgent->new; $ua->ssl_opts(verify_hostname => 0, SSL_verify_mode => 0x00); my $request = HTTP::Request->new(); $request->method($method); $request->uri($uri); $request->headers($header); my $response = $ua->request($request); print $counter_thread++, "th :", "Dumped Data Returned:\n\n ", sub +str ($response->decoded_content, 0, 256); print "Response code: ", $response->code, "\tHTTP Response Messag +e: ", $response->message, " "; print "Thread id: ", threads->tid(), "\n"; } my $thra = threads->create (\&getgoog); $thra-> join; my $thrb = threads->create (\&getgoog); $thrb-> join;
For clarity, the changes are:
What happens if you try running my code? You might also want to consider experimenting with not making warnings fatal.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: HTTP Request and Threads
by banhmi (Initiate) on Sep 13, 2018 at 20:24 UTC |