Skip to content

Commit 4e9532d

Browse files
committed
Remove deadlocking std logger
1 parent f6bc576 commit 4e9532d

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

examples/init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ def do_stuff
44
:stuff
55
end
66

7-
Concurrent.use_stdlib_logger Logger::DEBUG
7+
Concurrent.use_simple_logger Logger::DEBUG

lib/concurrent/configuration.rb

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,46 @@
1010
module Concurrent
1111
extend Concern::Logging
1212

13-
autoload :Options, 'concurrent/options'
14-
autoload :TimerSet, 'concurrent/executor/timer_set'
13+
autoload :Options, 'concurrent/options'
14+
autoload :TimerSet, 'concurrent/executor/timer_set'
1515
autoload :ThreadPoolExecutor, 'concurrent/executor/thread_pool_executor'
1616

1717
# @return [Logger] Logger with provided level and output.
18-
def self.create_stdlib_logger(level = Logger::FATAL, output = $stderr)
19-
logger = Logger.new(output)
20-
logger.level = level
21-
logger.formatter = lambda do |severity, datetime, progname, msg|
22-
formatted_message = case msg
18+
def self.create_simple_logger(level = Logger::FATAL, output = $stderr)
19+
# TODO (pitr-ch 24-Dec-2016): figure out why it had to be replaced, stdlogger was deadlocking
20+
lambda do |severity, progname, message = nil, &block|
21+
return false if severity < level
22+
23+
message = block ? block.call : message
24+
formatted_message = case message
2325
when String
24-
msg
26+
message
2527
when Exception
2628
format "%s (%s)\n%s",
27-
msg.message, msg.class, (msg.backtrace || []).join("\n")
29+
message.message, message.class, (message.backtrace || []).join("\n")
2830
else
29-
msg.inspect
31+
message.inspect
3032
end
31-
format "[%s] %5s -- %s: %s\n",
32-
datetime.strftime('%Y-%m-%d %H:%M:%S.%L'),
33-
severity,
34-
progname,
35-
formatted_message
36-
end
3733

38-
lambda do |loglevel, progname, message = nil, &block|
39-
logger.add loglevel, message, progname, &block
34+
output.print format "[%s] %5s -- %s: %s\n",
35+
Time.now.strftime('%Y-%m-%d %H:%M:%S.%L'),
36+
severity,
37+
progname,
38+
formatted_message
39+
true
4040
end
4141
end
4242

43-
# Use logger created by #create_stdlib_logger to log concurrent-ruby messages.
44-
def self.use_stdlib_logger(level = Logger::FATAL, output = $stderr)
45-
Concurrent.global_logger = create_stdlib_logger level, output
43+
# Use logger created by #create_simple_logger to log concurrent-ruby messages.
44+
def self.use_simple_logger(level = Logger::FATAL, output = $stderr)
45+
Concurrent.global_logger = create_simple_logger level, output
4646
end
4747

4848
# Suppresses all output when used for logging.
4949
NULL_LOGGER = lambda { |level, progname, message = nil, &block| }
5050

5151
# @!visibility private
52-
GLOBAL_LOGGER = AtomicReference.new(create_stdlib_logger(Logger::WARN))
52+
GLOBAL_LOGGER = AtomicReference.new(create_simple_logger(Logger::WARN))
5353
private_constant :GLOBAL_LOGGER
5454

5555
def self.global_logger
@@ -131,23 +131,23 @@ def self.executor(executor_identifier)
131131

132132
def self.new_fast_executor(opts = {})
133133
FixedThreadPool.new(
134-
[2, Concurrent.processor_count].max,
135-
auto_terminate: opts.fetch(:auto_terminate, true),
136-
idletime: 60, # 1 minute
137-
max_queue: 0, # unlimited
138-
fallback_policy: :abort # shouldn't matter -- 0 max queue
134+
[2, Concurrent.processor_count].max,
135+
auto_terminate: opts.fetch(:auto_terminate, true),
136+
idletime: 60, # 1 minute
137+
max_queue: 0, # unlimited
138+
fallback_policy: :abort # shouldn't matter -- 0 max queue
139139
)
140140
end
141141

142142
def self.new_io_executor(opts = {})
143143
ThreadPoolExecutor.new(
144-
min_threads: [2, Concurrent.processor_count].max,
145-
max_threads: ThreadPoolExecutor::DEFAULT_MAX_POOL_SIZE,
146-
# max_threads: 1000,
147-
auto_terminate: opts.fetch(:auto_terminate, true),
148-
idletime: 60, # 1 minute
149-
max_queue: 0, # unlimited
150-
fallback_policy: :abort # shouldn't matter -- 0 max queue
144+
min_threads: [2, Concurrent.processor_count].max,
145+
max_threads: ThreadPoolExecutor::DEFAULT_MAX_POOL_SIZE,
146+
# max_threads: 1000,
147+
auto_terminate: opts.fetch(:auto_terminate, true),
148+
idletime: 60, # 1 minute
149+
max_queue: 0, # unlimited
150+
fallback_policy: :abort # shouldn't matter -- 0 max queue
151151
)
152152
end
153153
end

spec/concurrent/edge/promises_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'concurrent/edge/promises'
22
require 'thread'
33

4-
Concurrent.use_stdlib_logger Logger::DEBUG
54

65
describe 'Concurrent::Promises' do
76

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
require 'concurrent'
2525
require 'concurrent-edge'
2626

27-
Concurrent.use_stdlib_logger Logger::FATAL
27+
Concurrent.use_simple_logger Logger::FATAL
2828

2929
# import all the support files
3030
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require File.expand_path(f) }

0 commit comments

Comments
 (0)