Issue2368

classification
Title: Problem with _io and BlockingIOError
Type: behaviour Severity: critical
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: akalinovski, zyasoft
Priority: Keywords:

Created on 2015-06-10.20:55:03 by akalinovski, last changed 2015-11-10.16:29:06 by zyasoft.

Messages
msg10108 (view) Author: akalinovski (akalinovski) Date: 2015-06-10.20:55:02
When trying to import any module which finally refers to io.py I got error about inability to import name BlockingIOError from _io. I figure out that it can be imported from _jyio but a lot of buil-in modules use _io directly (via using io.py)

Any help will be much appreciated.
msg10109 (view) Author: Jim Baker (zyasoft) Date: 2015-06-10.21:37:53
Sounds like we just need to export these names to _io. Should be quite reasonable to do.
msg10112 (view) Author: akalinovski (akalinovski) Date: 2015-06-10.21:54:01
Is it possible to get this fix any time soon? Is it very important for us to be able to use these modules.
msg10113 (view) Author: Jim Baker (zyasoft) Date: 2015-06-10.22:13:15
2.7.1 will be released in November, but we will have a couple of beta releases before then, which might work for you. The timing of the beta releases has not yet been planned. However, it would make sense to have the first one by end of August. Something we should certainly discuss on the jython-dev mailing list!
msg10114 (view) Author: akalinovski (akalinovski) Date: 2015-06-10.22:17:58
Ok, thanks for information. Is it possible to us to make a some local fix like overriding the module locally or somehow fix this issue before you release the milestone so we can proceed with further development in the meantime? Or it can be done only inside of jython itself only. Thanks in advance.
msg10115 (view) Author: Jim Baker (zyasoft) Date: 2015-06-10.22:31:05
Yes, you can readily monkeypatch to workaround for the time being:

$ jython27
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_45
Type "help", "copyright", "credits" or "license" for more information.
>>> import _io
>>> import _jyio
>>> dir(_jyio)
['BlockingIOError', 'BufferedRWPair', 'BufferedRandom', 'BufferedReader', 'BufferedWriter', 'BytesIO', 'DEFAULT_BUFFER_SIZE', 'EINTR', 'FileIO', 'IncrementalNewlineDecoder', 'Lock', 'StringIO', 'TextIOWrapper', 'UnsupportedOperation', '_BufferedIOBase', '_BufferedIOMixin', '_IOBase', '_RawIOBase', '_TextIOBase', '__builtins__', '__doc__', '__file__', '__metaclass__', '__name__', '__package__', '_check_buffered_bytes', '_check_decoded_chars', '_io', 'abc', 'array', 'codecs', 'errno', 'open', 'os', 'print_function', 'unicode_literals', 'warnings']
>>> _io.BlockingIOError = _jyio.BlockingIOError
>>> dir(_io)
['BlockingIOError', 'DEFAULT_BUFFER_SIZE', 'FileIO', 'UnsupportedOperation', '_IOBase', '_RawIOBase', '__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__doc__open', '__ensure_finalizer__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__name__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__subclasshook__', '__unicode__', 'class', 'equals', 'getClass', 'hashCode', 'notify', 'notifyAll', 'open', 'toString', 'wait']

Hope that helps! So the change is really simple, it's just that we have a release schedule we need to go through.
msg10116 (view) Author: akalinovski (akalinovski) Date: 2015-06-10.22:35:20
Ok, I will try this. Thanks!
msg10117 (view) Author: Jim Baker (zyasoft) Date: 2015-06-10.22:37:57
For completeness:

$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _io
>>> dir(_io)
['BlockingIOError', 'BufferedRWPair', 'BufferedRandom', 'BufferedReader', 'BufferedWriter', 'BytesIO', 'DEFAULT_BUFFER_SIZE', 'FileIO', 'IncrementalNewlineDecoder', 'StringIO', 'TextIOWrapper', 'UnsupportedOperation', '_BufferedIOBase', '_IOBase', '_RawIOBase', '_TextIOBase', '__doc__', '__file__', '__name__', '__package__', 'open']

$ jython27
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_45
Type "help", "copyright", "credits" or "license" for more information.
>>> import _io
>>> dir(_io)
['DEFAULT_BUFFER_SIZE', 'FileIO', 'UnsupportedOperation', '_IOBase', '_RawIOBase', '__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__doc__open', '__ensure_finalizer__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__name__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__subclasshook__', '__unicode__', 'class', 'equals', 'getClass', 'hashCode', 'notify', 'notifyAll', 'open', 'toString', 'wait']

Normally we would expect *undocumented* modules like _io to be implementation details, with code just using the io module (which defines BlockingIOError by importing from _jyio), but as we know, it's not always going to be the case for real code out there.
msg10118 (view) Author: akalinovski (akalinovski) Date: 2015-06-11.08:32:11
Thanks. That helped to fix this issue. But I've got further one: 

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/stringprep.py", line 8, in <module>
    from unicodedata import ucd_3_2_0 as unicodedata
ImportError: cannot import name ucd_3_2_0

I don't see it exported in unicodedata.py. Can it be used or it can be fixed somehow as well?

It is called from socket library and used in idna module. The full stack trace:

Exception in thread "main" Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/acitoolkit-0.2-py2.7.egg/acitoolkit/acitoolkit.py", line 36, in <module>
  File "/Library/Python/2.7/site-packages/acitoolkit-0.2-py2.7.egg/acitoolkit/aciphysobject.py", line 32, in <module>
  File "/Library/Python/2.7/site-packages/acitoolkit-0.2-py2.7.egg/acitoolkit/acibaseobject.py", line 35, in <module>
  File "/Library/Python/2.7/site-packages/acitoolkit-0.2-py2.7.egg/acitoolkit/acisession.py", line 35, in <module>
  File "/Library/Python/2.7/site-packages/requests-2.7.0-py2.7.egg/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/Library/Python/2.7/site-packages/requests-2.7.0-py2.7.egg/requests/utils.py", line 20, in <module>
    import socket
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 47, in <module>
    import _socket
  File "/Users/kailex/.m2/repository/org/python/jython-standalone/2.7.0/jython-standalone-2.7.0.jar/Lib/_socket.py", line 2, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/idna.py", line 3, in <module>
    import stringprep, re, codecs
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/stringprep.py", line 8, in <module>
    from unicodedata import ucd_3_2_0 as unicodedata
ImportError: cannot import name ucd_3_2_0
msg10119 (view) Author: akalinovski (akalinovski) Date: 2015-06-11.09:03:48
oh, nevermind. It looks like it's a pythongpath issue. Because of redundant paths it probably uses native socket rather than the one from jython.
msg10120 (view) Author: Jim Baker (zyasoft) Date: 2015-06-11.17:15:05
Yes, that's the bug in msg10119. I wonder if we should explicitly detect and warn if the CPython standard library is being used on the path - it does come up periodically.

On the other hand, it's easy enough to see in CPython itself!
msg10412 (view) Author: Jim Baker (zyasoft) Date: 2015-10-29.22:42:57
Need to expose these names, per msg10117. Should be a trivial and hopefully make the RC cutoff next week.
msg10427 (view) Author: Jim Baker (zyasoft) Date: 2015-11-01.20:39:51
Fixed as of https://hg.python.org/jython/rev/8e135fff613a
History
Date User Action Args
2015-11-10 16:29:06zyasoftsetstatus: pending -> closed
2015-11-01 20:39:52zyasoftsetstatus: open -> pending
resolution: accepted -> fixed
messages: + msg10427
2015-10-29 22:42:57zyasoftsetresolution: accepted
messages: + msg10412
2015-06-11 17:15:06zyasoftsetmessages: + msg10120
2015-06-11 09:03:49akalinovskisetmessages: + msg10119
2015-06-11 08:32:12akalinovskisetmessages: + msg10118
2015-06-10 22:37:58zyasoftsetmessages: + msg10117
2015-06-10 22:35:20akalinovskisetmessages: + msg10116
2015-06-10 22:31:06zyasoftsetmessages: + msg10115
2015-06-10 22:17:58akalinovskisetmessages: + msg10114
2015-06-10 22:13:16zyasoftsetmessages: + msg10113
2015-06-10 21:54:01akalinovskisetmessages: + msg10112
2015-06-10 21:38:00zyasoftsetmilestone: Jython 2.7.1
2015-06-10 21:37:53zyasoftsetnosy: + zyasoft
messages: + msg10109
2015-06-10 20:55:03akalinovskicreate