Skip to content

Commit

Permalink
ref #1 Use POSIX::Spawn::Child instead of #popen3 to avoid deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
nachokb committed May 10, 2018
1 parent 3ed148c commit ca1ac14
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/wicked_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
require 'digest/md5'
require 'rbconfig'

if (RbConfig::CONFIG['target_os'] =~ /mswin|mingw/) && (RUBY_VERSION < '1.9')
require 'win32/open3'
if ENV['WICKED_POPEN'] == 'ruby'
if (RbConfig::CONFIG['target_os'] =~ /mswin|mingw/) && (RUBY_VERSION < '1.9')
require 'win32/open3'
else
require 'open3'
end
else
require 'open3'
require 'posix/spawn'
end

begin
Expand Down Expand Up @@ -75,8 +79,13 @@ def pdf_from_url(url, options = {})

print_command(command.inspect) if in_development_mode?

err = Open3.popen3(*command) do |_stdin, _stdout, stderr|
stderr.read
err = if ENV['WICKED_POPEN'] == 'ruby'
Open3.popen3(*command) do |_stdin, _stdout, stderr|
stderr.read
end
else
child = POSIX::Spawn::Child.new(*command)
child.err
end
if options[:return_file]
return_file = options.delete(:return_file)
Expand Down
1 change: 1 addition & 0 deletions wicked_pdf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ DESC
spec.requirements << 'wkhtmltopdf'

spec.add_dependency 'activesupport'
spec.add_dependency 'posix-spawn', '~> 0.3.11'

spec.add_development_dependency 'rails'
spec.add_development_dependency 'bundler', '~> 1.3'
Expand Down

0 comments on commit ca1ac14

Please sign in to comment.