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 <1466892219.46.0.416121805197.issue27387@psf.upfronthosting.co.za>
In-reply-to
Content
This bug manifest itself in at least one very specific situation:

    1. No locale is set on the machine
    2. A file (test1.py) imports a second (test2.py)
    3. The second file (test2.py) 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        

    $

[test1.py]:

    import test2

[test2.py]:

    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()
    t.start()
    t.join()

    print 'done'

[Expected behavior]:

    $ python test1.py                                                                         
    Error from server: code=000a
    done

[Actual behavior]: 

    $ python test1.py                                                                         
    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 (https://datastax-oss.atlassian.net/browse/PYTHON-592).

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

[test1.py']:

    "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.
History
Date User Action Args
2016-06-25 22:03:39joshpurvissetrecipients: + joshpurvis, vstinner, ezio.melotti
2016-06-25 22:03:39joshpurvissetmessageid: <1466892219.46.0.416121805197.issue27387@psf.upfronthosting.co.za>
2016-06-25 22:03:39joshpurvislinkissue27387 messages
2016-06-25 22:03:38joshpurviscreate