This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author joshpurvis
Recipients ezio.melotti, joshpurvis, vstinner
Date 2016-06-25.22:03:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This bug manifest itself in at least one very specific situation:

    1. No locale is set on the machine
    2. A file ( imports a second (
    3. The second file ( calls str.encode() from inside a thread
    4. Running Python 2.7

[Environment with no locale set]:

    # both of these are unset:
    $ echo $LC_CTYPE

    $ echo $LANG        



    import test2


    from threading import Thread

    class TestThread(Thread):
        def run(self):
            msg = 'Error from server: code=000a'
            print msg
            msg = msg.encode('utf-8')

    t = TestThread()

    print 'done'

[Expected behavior]:

    $ python                                                                         
    Error from server: code=000a

[Actual behavior]: 

    $ python                                                                         
    Error from server: code=000a
    [script hangs here indefinitely]

Much thanks to Alan Boudreault, a developer of the cassandra-driver Python package, for helping me locate this bug and further narrow it down to the threading module. The above code snippet was copied from his comment on my issue over there (

Another curious behavior is that if you modify to decode any string prior to the import, it implicitly fixes the issue:


    "any string".decode('utf-8')
    import test2

I realize that one should probably always have a locale set, however, this proved to be very difficult to isolate, especially given that it works if no import occurs or a string is decoded prior to the import.
Date User Action Args
2016-06-25 22:03:39joshpurvissetrecipients: + joshpurvis, vstinner, ezio.melotti
2016-06-25 22:03:39joshpurvissetmessageid: <>
2016-06-25 22:03:39joshpurvislinkissue27387 messages
2016-06-25 22:03:38joshpurviscreate