diff --git a/IntegrationTests/tests_04_performance/Thresholds/5.10.json b/IntegrationTests/tests_04_performance/Thresholds/5.10.json index ecf2101b4..844e97841 100644 --- a/IntegrationTests/tests_04_performance/Thresholds/5.10.json +++ b/IntegrationTests/tests_04_performance/Thresholds/5.10.json @@ -19,7 +19,7 @@ "1000_udp_reqs": 6050, "1000_udpbootstraps": 2050, "1000_udpconnections": 75050, - "1_reqs_1000_conn": 389050, + "1_reqs_1000_conn": 384050, "bytebuffer_lots_of_rw": 2050, "creating_10000_headers": 0, "decode_1000_ws_frames": 2050, @@ -41,7 +41,7 @@ "get_100000_headers_canonical_form_trimming_whitespace_from_short_string": 700050, "modifying_1000_circular_buffer_elements": 0, "modifying_byte_buffer_view": 6050, - "ping_pong_1000_reqs_1_conn": 319, + "ping_pong_1000_reqs_1_conn": 314, "read_10000_chunks_from_file": 110050, "schedule_10000_tasks": 40100, "schedule_and_run_10000_tasks": 50050, diff --git a/IntegrationTests/tests_04_performance/Thresholds/5.9.json b/IntegrationTests/tests_04_performance/Thresholds/5.9.json index edd71c82f..6e9df5a2f 100644 --- a/IntegrationTests/tests_04_performance/Thresholds/5.9.json +++ b/IntegrationTests/tests_04_performance/Thresholds/5.9.json @@ -19,7 +19,7 @@ "1000_udp_reqs": 6050, "1000_udpbootstraps": 2050, "1000_udpconnections": 75050, - "1_reqs_1000_conn": 398050, + "1_reqs_1000_conn": 393050, "bytebuffer_lots_of_rw": 2050, "creating_10000_headers": 0, "decode_1000_ws_frames": 2050, @@ -41,7 +41,7 @@ "get_100000_headers_canonical_form_trimming_whitespace_from_short_string": 700050, "modifying_1000_circular_buffer_elements": 0, "modifying_byte_buffer_view": 6050, - "ping_pong_1000_reqs_1_conn": 334, + "ping_pong_1000_reqs_1_conn": 329, "read_10000_chunks_from_file": 110050, "schedule_10000_tasks": 40100, "schedule_and_run_10000_tasks": 50050, diff --git a/IntegrationTests/tests_04_performance/Thresholds/6.0.json b/IntegrationTests/tests_04_performance/Thresholds/6.0.json index ecf2101b4..5235f29b3 100644 --- a/IntegrationTests/tests_04_performance/Thresholds/6.0.json +++ b/IntegrationTests/tests_04_performance/Thresholds/6.0.json @@ -19,7 +19,7 @@ "1000_udp_reqs": 6050, "1000_udpbootstraps": 2050, "1000_udpconnections": 75050, - "1_reqs_1000_conn": 389050, + "1_reqs_1000_conn": 384000, "bytebuffer_lots_of_rw": 2050, "creating_10000_headers": 0, "decode_1000_ws_frames": 2050, @@ -41,7 +41,7 @@ "get_100000_headers_canonical_form_trimming_whitespace_from_short_string": 700050, "modifying_1000_circular_buffer_elements": 0, "modifying_byte_buffer_view": 6050, - "ping_pong_1000_reqs_1_conn": 319, + "ping_pong_1000_reqs_1_conn": 314, "read_10000_chunks_from_file": 110050, "schedule_10000_tasks": 40100, "schedule_and_run_10000_tasks": 50050, diff --git a/IntegrationTests/tests_04_performance/Thresholds/nightly-6.0.json b/IntegrationTests/tests_04_performance/Thresholds/nightly-6.0.json index ecf2101b4..5235f29b3 100644 --- a/IntegrationTests/tests_04_performance/Thresholds/nightly-6.0.json +++ b/IntegrationTests/tests_04_performance/Thresholds/nightly-6.0.json @@ -19,7 +19,7 @@ "1000_udp_reqs": 6050, "1000_udpbootstraps": 2050, "1000_udpconnections": 75050, - "1_reqs_1000_conn": 389050, + "1_reqs_1000_conn": 384000, "bytebuffer_lots_of_rw": 2050, "creating_10000_headers": 0, "decode_1000_ws_frames": 2050, @@ -41,7 +41,7 @@ "get_100000_headers_canonical_form_trimming_whitespace_from_short_string": 700050, "modifying_1000_circular_buffer_elements": 0, "modifying_byte_buffer_view": 6050, - "ping_pong_1000_reqs_1_conn": 319, + "ping_pong_1000_reqs_1_conn": 314, "read_10000_chunks_from_file": 110050, "schedule_10000_tasks": 40100, "schedule_and_run_10000_tasks": 50050, diff --git a/IntegrationTests/tests_04_performance/Thresholds/nightly-main.json b/IntegrationTests/tests_04_performance/Thresholds/nightly-main.json index 36eadc747..5500c5235 100644 --- a/IntegrationTests/tests_04_performance/Thresholds/nightly-main.json +++ b/IntegrationTests/tests_04_performance/Thresholds/nightly-main.json @@ -19,7 +19,7 @@ "1000_udp_reqs": 6050, "1000_udpbootstraps": 2050, "1000_udpconnections": 75050, - "1_reqs_1000_conn": 389050, + "1_reqs_1000_conn": 384050, "bytebuffer_lots_of_rw": 2050, "creating_10000_headers": 0, "decode_1000_ws_frames": 2050, @@ -41,7 +41,7 @@ "get_100000_headers_canonical_form_trimming_whitespace_from_short_string": 500050, "modifying_1000_circular_buffer_elements": 0, "modifying_byte_buffer_view": 6050, - "ping_pong_1000_reqs_1_conn": 319, + "ping_pong_1000_reqs_1_conn": 314, "read_10000_chunks_from_file": 110050, "schedule_10000_tasks": 40100, "schedule_and_run_10000_tasks": 50050, diff --git a/Sources/NIOPosix/Bootstrap.swift b/Sources/NIOPosix/Bootstrap.swift index 6d1312b6a..1ea1d311f 100644 --- a/Sources/NIOPosix/Bootstrap.swift +++ b/Sources/NIOPosix/Bootstrap.swift @@ -386,7 +386,7 @@ public final class ServerBootstrap { private func bind0( makeServerChannel: (_ eventLoop: SelectableEventLoop, _ childGroup: EventLoopGroup, _ enableMPTCP: Bool) throws -> ServerSocketChannel, - _ register: @escaping (EventLoop, ServerSocketChannel) -> EventLoopFuture + _ register: @escaping @Sendable (EventLoop, ServerSocketChannel) -> EventLoopFuture ) -> EventLoopFuture { let eventLoop = self.group.next() let childEventLoopGroup = self.childGroup @@ -410,15 +410,18 @@ public final class ServerBootstrap { serverChannelOptions.applyAllChannelOptions(to: serverChannel).flatMap { serverChannelInit(serverChannel) }.flatMap { - serverChannel.pipeline.addHandler( - AcceptHandler( - childChannelInitializer: childChannelInit, - childChannelOptions: childChannelOptions - ), - name: "AcceptHandler" - ) - }.flatMap { - register(eventLoop, serverChannel) + do { + try serverChannel.pipeline.syncOperations.addHandler( + AcceptHandler( + childChannelInitializer: childChannelInit, + childChannelOptions: childChannelOptions + ), + name: "AcceptHandler" + ) + return register(eventLoop, serverChannel) + } catch { + return eventLoop.makeFailedFuture(error) + } }.map { serverChannel as Channel }.flatMapError { error in @@ -434,11 +437,11 @@ public final class ServerBootstrap { public typealias InboundIn = SocketChannel public typealias InboundOut = SocketChannel - private let childChannelInit: ((Channel) -> EventLoopFuture)? + private let childChannelInit: (@Sendable (Channel) -> EventLoopFuture)? private let childChannelOptions: ChannelOptions.Storage init( - childChannelInitializer: ((Channel) -> EventLoopFuture)?, + childChannelInitializer: (@Sendable (Channel) -> EventLoopFuture)?, childChannelOptions: ChannelOptions.Storage ) { self.childChannelInit = childChannelInitializer @@ -461,10 +464,12 @@ public final class ServerBootstrap { let ctxEventLoop = context.eventLoop let childEventLoop = accepted.eventLoop let childChannelInit = self.childChannelInit ?? { (_: Channel) in childEventLoop.makeSucceededFuture(()) } + let childChannelOptions = self.childChannelOptions @inline(__always) + @Sendable func setupChildChannel() -> EventLoopFuture { - self.childChannelOptions.applyAllChannelOptions(to: accepted).flatMap { () -> EventLoopFuture in + childChannelOptions.applyAllChannelOptions(to: accepted).flatMap { () -> EventLoopFuture in childEventLoop.assertInEventLoop() return childChannelInit(accepted) } @@ -472,20 +477,17 @@ public final class ServerBootstrap { @inline(__always) func fireThroughPipeline(_ future: EventLoopFuture, context: ChannelHandlerContext) { + // Strictly these asserts are redundant with future.assumeIsolated(), but as this code + // has guarantees that can be quite hard to follow we keep them here. ctxEventLoop.assertInEventLoop() assert(ctxEventLoop === context.eventLoop) - let loopBoundContext = context.loopBound - future.flatMap { (_) -> EventLoopFuture in - let context = loopBoundContext.value - ctxEventLoop.assertInEventLoop() + future.assumeIsolated().flatMap { (_) -> EventLoopFuture in guard context.channel.isActive else { return ctxEventLoop.makeFailedFuture(ChannelError._ioOnClosedChannel) } context.fireChannelRead(Self.wrapInboundOut(accepted)) return context.eventLoop.makeSucceededFuture(()) }.whenFailure { error in - let context = loopBoundContext.value - ctxEventLoop.assertInEventLoop() self.closeAndFire(context: context, accepted: accepted, err: error) } } @@ -770,10 +772,9 @@ extension Channel { // implementation, `epoll` will send us `EPOLLHUP`. To have it run synchronously, we need to invoke the // `flatMap` on the eventloop that the `register` will succeed on. self.eventLoop.assertInEventLoop() - return self.register().flatMap { - self.eventLoop.assertInEventLoop() - return body(self) - } + return self.register().assumeIsolated().flatMap { + body(self) + }.nonisolated() } } @@ -811,8 +812,8 @@ public final class ClientBootstrap: NIOClientTCPBootstrapProtocol { if let protocolHandlers = self.protocolHandlers { let channelInitializer = _channelInitializer return { channel in - channelInitializer(channel).flatMap { - channel.pipeline.addHandlers(protocolHandlers(), position: .first) + channelInitializer(channel).hop(to: channel.eventLoop).flatMapThrowing { + try channel.pipeline.syncOperations.addHandlers(protocolHandlers(), position: .first) } } } else { @@ -1005,11 +1006,14 @@ public final class ClientBootstrap: NIOClientTCPBootstrapProtocol { return connector.resolveAndConnect() } - private func connect(freshChannel channel: Channel, address: SocketAddress) -> EventLoopFuture { + private static func connect( + freshChannel channel: Channel, + address: SocketAddress, + connectTimeout: TimeAmount + ) -> EventLoopFuture { let connectPromise = channel.eventLoop.makePromise(of: Void.self) channel.connect(to: address, promise: connectPromise) - let cancelTask = channel.eventLoop.scheduleTask(in: self.connectTimeout) { - [connectTimeout = self.connectTimeout] in + let cancelTask = channel.eventLoop.scheduleTask(in: connectTimeout) { connectPromise.fail(ChannelError.connectTimeout(connectTimeout)) channel.close(promise: nil) } @@ -1024,8 +1028,9 @@ public final class ClientBootstrap: NIOClientTCPBootstrapProtocol { injectedChannel: SocketChannel, to address: SocketAddress ) -> EventLoopFuture { - self.initializeAndRegisterChannel(injectedChannel) { channel in - self.connect(freshChannel: channel, address: address) + let connectTimeout = self.connectTimeout + return self.initializeAndRegisterChannel(injectedChannel) { channel in + Self.connect(freshChannel: channel, address: address, connectTimeout: connectTimeout) } } @@ -1035,11 +1040,13 @@ public final class ClientBootstrap: NIOClientTCPBootstrapProtocol { /// - address: The address to connect to. /// - Returns: An `EventLoopFuture` to deliver the `Channel` when connected. public func connect(to address: SocketAddress) -> EventLoopFuture { - self.initializeAndRegisterNewChannel( + let connectTimeout = self.connectTimeout + + return self.initializeAndRegisterNewChannel( eventLoop: self.group.next(), protocolFamily: address.protocol ) { channel in - self.connect(freshChannel: channel, address: address) + Self.connect(freshChannel: channel, address: address, connectTimeout: connectTimeout) } } @@ -1103,6 +1110,8 @@ public final class ClientBootstrap: NIOClientTCPBootstrapProtocol { public func withConnectedSocket(_ socket: NIOBSDSocket.Handle) -> EventLoopFuture { let eventLoop = group.next() let channelInitializer = self.channelInitializer + let options = self._channelOptions + let channel: SocketChannel do { channel = try SocketChannel(eventLoop: eventLoop as! SelectableEventLoop, socket: socket) @@ -1110,9 +1119,10 @@ public final class ClientBootstrap: NIOClientTCPBootstrapProtocol { return eventLoop.makeFailedFuture(error) } + @Sendable func setupChannel() -> EventLoopFuture { eventLoop.assertInEventLoop() - return self._channelOptions.applyAllChannelOptions(to: channel).flatMap { + return options.applyAllChannelOptions(to: channel).flatMap { channelInitializer(channel) }.flatMap { eventLoop.assertInEventLoop() @@ -1137,7 +1147,7 @@ public final class ClientBootstrap: NIOClientTCPBootstrapProtocol { private func initializeAndRegisterNewChannel( eventLoop: EventLoop, protocolFamily: NIOBSDSocket.ProtocolFamily, - _ body: @escaping (Channel) -> EventLoopFuture + _ body: @escaping @Sendable (Channel) -> EventLoopFuture ) -> EventLoopFuture { let channel: SocketChannel do { @@ -1150,16 +1160,18 @@ public final class ClientBootstrap: NIOClientTCPBootstrapProtocol { private func initializeAndRegisterChannel( _ channel: SocketChannel, - _ body: @escaping (Channel) -> EventLoopFuture + _ body: @escaping @Sendable (Channel) -> EventLoopFuture ) -> EventLoopFuture { let channelInitializer = self.channelInitializer let channelOptions = self._channelOptions let eventLoop = channel.eventLoop + let bindTarget = self.bindTarget @inline(__always) + @Sendable func setupChannel() -> EventLoopFuture { eventLoop.assertInEventLoop() - return channelOptions.applyAllChannelOptions(to: channel).flatMap { [bindTarget = self.bindTarget] in + return channelOptions.applyAllChannelOptions(to: channel).flatMap { if let bindTarget = bindTarget { return channel.bind(to: bindTarget).flatMap { channelInitializer(channel) @@ -1230,6 +1242,7 @@ extension ClientBootstrap { channelInitializer: @escaping @Sendable (Channel) -> EventLoopFuture ) async throws -> Output { let eventLoop = self.group.next() + let connectTimeout = self.connectTimeout return try await self.initializeAndRegisterNewChannel( eventLoop: eventLoop, protocolFamily: address.protocol, @@ -1238,7 +1251,7 @@ extension ClientBootstrap { eventLoop.makeSucceededFuture(output) }, { channel in - self.connect(freshChannel: channel, address: address) + Self.connect(freshChannel: channel, address: address, connectTimeout: connectTimeout) } ).get().1 } @@ -1322,7 +1335,7 @@ extension ClientBootstrap { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) - func connect( + func connect( host: String, port: Int, eventLoop: EventLoop, @@ -1359,7 +1372,10 @@ extension ClientBootstrap { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) - private func withConnectedSocket( + private func withConnectedSocket< + ChannelInitializerResult: Sendable, + PostRegistrationTransformationResult: Sendable + >( eventLoop: EventLoop, socket: NIOBSDSocket.Handle, channelInitializer: @escaping @Sendable (Channel) -> EventLoopFuture, @@ -1382,14 +1398,17 @@ extension ClientBootstrap { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) - private func initializeAndRegisterNewChannel( + private func initializeAndRegisterNewChannel< + ChannelInitializerResult: Sendable, + PostRegistrationTransformationResult: Sendable + >( eventLoop: EventLoop, protocolFamily: NIOBSDSocket.ProtocolFamily, channelInitializer: @escaping @Sendable (Channel) -> EventLoopFuture, postRegisterTransformation: @escaping @Sendable (ChannelInitializerResult, EventLoop) -> EventLoopFuture< PostRegistrationTransformationResult >, - _ body: @escaping (Channel) -> EventLoopFuture + _ body: @escaping @Sendable (Channel) -> EventLoopFuture ) -> EventLoopFuture<(Channel, PostRegistrationTransformationResult)> { let channel: SocketChannel do { @@ -1408,7 +1427,10 @@ extension ClientBootstrap { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) - private func initializeAndRegisterChannel( + private func initializeAndRegisterChannel< + ChannelInitializerResult: Sendable, + PostRegistrationTransformationResult: Sendable + >( channel: SocketChannel, channelInitializer: @escaping @Sendable (Channel) -> EventLoopFuture, registration: @escaping @Sendable (SocketChannel) -> EventLoopFuture, @@ -1416,9 +1438,12 @@ extension ClientBootstrap { PostRegistrationTransformationResult > ) -> EventLoopFuture { - let channelInitializer = { channel in - self.channelInitializer(channel) + let bootstrapChannelInitializer = self.channelInitializer + let channelInitializer = { @Sendable channel in + bootstrapChannelInitializer(channel).hop(to: channel.eventLoop) + .assumeIsolated() .flatMap { channelInitializer(channel) } + .nonisolated() } let channelOptions = self._channelOptions let eventLoop = channel.eventLoop @@ -1431,6 +1456,7 @@ extension ClientBootstrap { return channelOptions .applyAllChannelOptions(to: channel) + .assumeIsolated() .flatMap { if let bindTarget = bindTarget { return @@ -1455,6 +1481,7 @@ extension ClientBootstrap { channel.close0(error: error, mode: .all, promise: nil) return channel.eventLoop.makeFailedFuture(error) } + .nonisolated() } if eventLoop.inEventLoop { @@ -1708,10 +1735,10 @@ public final class DatagramBootstrap { private func withNewChannel( makeChannel: (_ eventLoop: SelectableEventLoop) throws -> DatagramChannel, - _ bringup: @escaping (EventLoop, DatagramChannel) -> EventLoopFuture + _ bringup: @escaping @Sendable (EventLoop, DatagramChannel) -> EventLoopFuture ) -> EventLoopFuture { let eventLoop = self.group.next() - let channelInitializer = self.channelInitializer ?? { _ in eventLoop.makeSucceededFuture(()) } + let channelInitializer = self.channelInitializer ?? { @Sendable _ in eventLoop.makeSucceededFuture(()) } let channelOptions = self._channelOptions let channel: DatagramChannel @@ -1721,6 +1748,7 @@ public final class DatagramBootstrap { return eventLoop.makeFailedFuture(error) } + @Sendable func setupChannel() -> EventLoopFuture { eventLoop.assertInEventLoop() return channelOptions.applyAllChannelOptions(to: channel).flatMap { @@ -1927,7 +1955,7 @@ extension DatagramBootstrap { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) - private func connect0( + private func connect0( makeSocketAddress: () throws -> SocketAddress, channelInitializer: @escaping @Sendable (Channel) -> EventLoopFuture, postRegisterTransformation: @escaping @Sendable (ChannelInitializerResult, EventLoop) -> EventLoopFuture< @@ -1958,7 +1986,7 @@ extension DatagramBootstrap { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) - private func bind0( + private func bind0( makeSocketAddress: () throws -> SocketAddress, channelInitializer: @escaping @Sendable (Channel) -> EventLoopFuture, postRegisterTransformation: @escaping @Sendable (ChannelInitializerResult, EventLoop) -> EventLoopFuture< @@ -1989,7 +2017,10 @@ extension DatagramBootstrap { } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) - private func makeConfiguredChannel( + private func makeConfiguredChannel< + ChannelInitializerResult: Sendable, + PostRegistrationTransformationResult: Sendable + >( makeChannel: (_ eventLoop: SelectableEventLoop) throws -> DatagramChannel, channelInitializer: @escaping @Sendable (Channel) -> EventLoopFuture, registration: @escaping @Sendable (Channel) -> EventLoopFuture, @@ -1998,9 +2029,14 @@ extension DatagramBootstrap { > ) -> EventLoopFuture { let eventLoop = self.group.next() - let channelInitializer = { (channel: Channel) -> EventLoopFuture in - let initializer = self.channelInitializer ?? { _ in eventLoop.makeSucceededFuture(()) } - return initializer(channel).flatMap { channelInitializer(channel) } + let bootstrapChannelInitializer = + self.channelInitializer ?? { @Sendable _ in eventLoop.makeSucceededFuture(()) } + let channelInitializer = { @Sendable (channel: Channel) -> EventLoopFuture in + bootstrapChannelInitializer(channel) + .hop(to: channel.eventLoop) + .assumeIsolated() + .flatMap { channelInitializer(channel) } + .nonisolated() } let channelOptions = self._channelOptions @@ -2011,6 +2047,7 @@ extension DatagramBootstrap { return eventLoop.makeFailedFuture(error) } + @Sendable func setupChannel() -> EventLoopFuture { eventLoop.assertInEventLoop() return channelOptions.applyAllChannelOptions(to: channel).flatMap { diff --git a/dev/malloc-aggregation.d b/dev/malloc-aggregation.d index a0c2f3aa4..af9803fc3 100755 --- a/dev/malloc-aggregation.d +++ b/dev/malloc-aggregation.d @@ -28,17 +28,24 @@ printf("=====\n"); } +pid$target::aligned_alloc:entry, +pid$target::calloc:entry, pid$target::malloc:entry, pid$target::posix_memalign:entry, pid$target::realloc:entry, pid$target::reallocf:entry, -pid$target::calloc:entry, pid$target::valloc:entry, -pid$target::malloc_zone_malloc:entry, -pid$target::malloc_zone_realloc:entry, +pid$target::malloc_type_aligned_alloc:entry, +pid$target::malloc_type_calloc:entry, +pid$target::malloc_type_malloc:entry, +pid$target::malloc_type_posix_memalign:entry, +pid$target::malloc_type_realloc:entry, +pid$target::malloc_type_valloc:entry, pid$target::malloc_zone_calloc:entry, -pid$target::malloc_zone_valloc:entry, -pid$target::malloc_zone_memalign:entry { +pid$target::malloc_zone_malloc:entry, +pid$target::malloc_zone_memalign:entry, +pid$target::malloc_zone_realloc:entry, +pid$target::malloc_zone_valloc:entry { @malloc_calls[ustack()] = count(); } diff --git a/dev/stackdiff-dtrace.py b/dev/stackdiff-dtrace.py index 6f95335f5..a277915d6 100755 --- a/dev/stackdiff-dtrace.py +++ b/dev/stackdiff-dtrace.py @@ -17,7 +17,7 @@ import collections import re import sys -num_regex = "^ +([0-9]+)$" +num_regex = b"^ +([0-9]+)$" def put_in_dict(path): @@ -54,10 +54,10 @@ def put_in_dict(path): # libswiftCore.dylib`swift_allocObject+0x27 # (truncated) dictionary = collections.defaultdict(list) - with open(path, "r") as f: + with open(path, "rb") as f: current_stack = [] for line in f: - if not line.startswith(" "): + if not line.startswith(b" "): # All lines we're intereted in are indented so ignore this one. pass elif re.match(num_regex, line): @@ -69,10 +69,10 @@ def put_in_dict(path): # everything before the '+'. We only take at most the first 8 # lines for the key so that we group 'similar' stacks in our # output. - key = "\n".join(line.split("+")[0] for line in current_stack[:8]) + key = b"\n".join(line.split(b"+")[0] for line in current_stack[:8]) # Record this stack and reset our state to build a new one. - dictionary[key].append((int(line), "\n".join(current_stack))) + dictionary[key].append((int(line), b"\n".join(current_stack))) current_stack = [] else: # This line doesn't contain just a number. This might be an @@ -106,7 +106,7 @@ def extract_useful_keys(d): def print_dictionary_member(d, key): print(total_count_for_key(d, key)) - print(key) + print(key.decode('utf8')) print() print_dictionary_member_detail(d, key) print() @@ -116,7 +116,7 @@ def print_dictionary_member_detail(d, key): value = d[key] for (count, stack) in value: print(" %d" % count) - print(" " + stack.replace("\n", "\n ")) + print((b" " + stack.replace(b"\n", b"\n ")).decode('utf8')) def usage():