#!/usr/bin/env python3 """ Foo is a subclass of str, and uses __new__. Goo is a nearly identical class, but uses __init__. When the Foo constructor is called via a multiprocessing Pool, the call stack somehow gets garbled, and the output gets sent right back into the constructor: Called Foo.__new__ with args = (u'TIMESTAMP', u'INPUT0') Called Foo.__new__ with args = ('TIMESTAMP OUTPUT0',) When Foo is swapped out for Goo, the expected result is obtained: Called Goo.__init__ with args = (u'TIMESTAMP', u'INPUT0') The problem also goes away when a multiprocessing.pool.ThreadPool is used instead of a (process) Pool: Called Foo.__new__ with args = (u'TIMESTAMP', u'INPUT0') TIMESTAMP OUTPUT0 Seen in Python 2.7.9 and 3.4.5 """ from __future__ import print_function, unicode_literals import multiprocessing.pool as mpp import multiprocessing as mp # ###################################################################### def main(): # pool = mpp.ThreadPool(1) pool = mp.Pool(1) getter = pool.apply_async( Foo, ('TIMESTAMP', 'INPUT0'), {} ) print( getter.get(timeout=3) ) pool.close() return # ###################################################################### class Foo(str): def __new__(cls, *args): print( 'Called Foo.__new__ with args = ' + repr(args) ) if len(args) != 2: raise ValueError( 'Bad Foo input: ' + repr(args) ) tmp = args[0] + ' ' + args[1].replace('INPUT', 'OUTPUT') return str.__new__(cls, tmp) # ###################################################################### class Goo(object): def __init__(self, *args): print( 'Called Goo.__init__ with args = ' + repr(args) ) if len(args) != 2: raise ValueError( 'Bad Goo input: ' + repr(args) ) self.name = args[0] + ' ' + args[1].replace('INPUT', 'OUTPUT') return def __repr__(self): return '' # ###################################################################### if __name__ == '__main__': main()