row_compressors append(compressorcompressed bytearray(for compressor in row_compressorscompressed extend(compressor result()return compressed this example barely needs explainingit splits the incoming bits into rows based on the width of the image using the same split_bits function we have already defined (hooray for bottom-up design!note that this code will compress any sequence of bitsalthough it would bloatrather than compress binary data that has frequent changes in bit values black and white images are definitely good candidates for the compression algorithm in question let' now create function that loads an image file using the third-party pillow moduleconverts it to bitsand compresses it we can easily switch between executors using the venerable comment statementfrom pil import image def compress_image(in_filenameout_filenameexecutor=none)executor executor if executor else processpoolexecutor(with image open(in_filenameas imagebits bitarray(image convert(' 'getdata()widthheight image size compressed compress_in_executor(executorbitswidthwith open(out_filename'wb'as filefile write(width to_bytes( 'little')file write(height to_bytes( 'little')file write(compresseddef single_image_main()in_filenameout_filename sys argv[ : #executor threadpoolexecutor( executor processpoolexecutor(compress_image(in_filenameout_filenameexecutorthe image convert(call changes the image to black and white (one bitmodewhile getdata(returns an iterator over those values we pack the results into bitarray so they transfer across the wire more quickly when we output the compressed filewe first write the width and height of the image followed by the compressed datawhich arrives as bytearraywhich can be written directly to the binary file