[issue27387] Thread hangs on str.encode() when locale is not set

2016-06-25 Thread Josh Purvis

New submission from Josh Purvis:

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.

--
components: Interpreter Core, Unicode
messages: 269262
nosy: ezio.melotti, haypo, joshpurvis
priority: normal
severity: normal
status: open
title: Thread hangs on str.encode() when locale is not set
type: behavior
versions: Python 2.7

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27387>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17981] SysLogHandler closes connection before using it

2013-05-15 Thread Josh Purvis

Changes by Josh Purvis joshua.pur...@gmail.com:


--
nosy: +Josh.Purvis

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17981
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17981] SysLogHandler closes connection before using it

2013-05-15 Thread Josh Purvis

Josh Purvis added the comment:

Ironically, I ran into this same exact issue today, and I have investigated the 
`files_preserve` param, with no luck. I'm not too familiar with the internals 
here, but from what I can tell it works with FileHandler, but not the 
SysLogHandler. 

If you try to add the syslog handler to the files_preserve list it has no 
effect. It seems to need a stream, and SysLogHandler doesn't have the stream 
attribute.

# This works for FileHandler's
log = logging.getLogger('MyLog')
fh = logging.FileHandler('/some/file')

with daemon.DaemonContext(files_preserve=[fh.stream, ]):
   log.warn(In the belly of the beast.)

--
status: pending - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17981
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com