Issue1943

classification
Title: missing module fcntl
Type: behaviour Severity: normal
Components: Any Versions: Jython 2.7
Milestone:
process
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: amak, fwierzbicki, stefan.richthofer, wbrana, zyasoft
Priority: low Keywords:

Created on 2012-07-01.10:30:37 by wbrana, last changed 2018-03-07.19:14:17 by jeff.allen.

Messages
msg7297 (view) Author: (wbrana) Date: 2012-07-01.10:30:36
Jython 2.7.0a2+ (default:e4afcd777d1b+, Jul 1 2012, 12:22:26) 
[Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_33
Type "help", "copyright", "credits" or "license" for more information.
>>> import fcntl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named fcntl
>>> 
inst@local /mnt/md3/cache/inst/jython2 $ python
Python 2.7.3 (default, May  5 2012, 10:54:18) 
[GCC 4.4.7] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import fcntl
>>> dir(fcntl)
['DN_ACCESS', 'DN_ATTRIB', 'DN_CREATE', 'DN_DELETE', 'DN_MODIFY', 'DN_MULTISHOT', 'DN_RENAME', 'FASYNC', 'FD_CLOEXEC', 'F_DUPFD', 'F_EXLCK', 'F_GETFD', 'F_GETFL', 'F_GETLEASE', 'F_GETLK', 'F_GETLK64', 'F_GETOWN', 'F_GETSIG', 'F_NOTIFY', 'F_RDLCK', 'F_SETFD', 'F_SETFL', 'F_SETLEASE', 'F_SETLK', 'F_SETLK64', 'F_SETLKW', 'F_SETLKW64', 'F_SETOWN', 'F_SETSIG', 'F_SHLCK', 'F_UNLCK', 'F_WRLCK', 'I_ATMARK', 'I_CANPUT', 'I_CKBAND', 'I_FDINSERT', 'I_FIND', 'I_FLUSH', 'I_FLUSHBAND', 'I_GETBAND', 'I_GETCLTIME', 'I_GETSIG', 'I_GRDOPT', 'I_GWROPT', 'I_LINK', 'I_LIST', 'I_LOOK', 'I_NREAD', 'I_PEEK', 'I_PLINK', 'I_POP', 'I_PUNLINK', 'I_PUSH', 'I_RECVFD', 'I_SENDFD', 'I_SETCLTIME', 'I_SETSIG', 'I_SRDOPT', 'I_STR', 'I_SWROPT', 'I_UNLINK', 'LOCK_EX', 'LOCK_MAND', 'LOCK_NB', 'LOCK_READ', 'LOCK_RW', 'LOCK_SH', 'LOCK_UN', 'LOCK_WRITE', '__doc__', '__file__', '__name__', '__package__', 'fcntl', 'flock', 'ioctl', 'lockf']
msg7517 (view) Author: Alan Kennedy (amak) Date: 2012-11-07.22:39:05
"""
35.10. fcntl — The fcntl() and ioctl() system calls

Platforms: Unix

This module performs file control and I/O control on file descriptors. It is an interface to the fcntl() and ioctl() Unix routines.
"""

http://docs.python.org/2/library/fcntl.html

DO you expect that this should work on jython on non-Unix platforms?

Should it work on Windows? It doesn't on cpython.

What do you want to use the fcntl module for?
msg7713 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-20.00:18:21
I don't think this one makes sense for us, closing.
msg10484 (view) Author: Jim Baker (zyasoft) Date: 2015-11-17.16:35:29
Let's reopen this. It's still a low priority, but it should be eminently doable for 2.7.2, given that JNR already supports this functionality:

https://github.com/jnr/jnr-posix/blob/master/src/main/java/jnr/posix/LazyPOSIX.java#L423

Through the ugliness that is PosixModule#getFD, we already support int file descriptors where possible (at least for files that are not sockets), so this would be a straightforward addition.
msg10485 (view) Author: Jim Baker (zyasoft) Date: 2015-11-17.16:41:08
A real test of how far we can push fcntl will be working with os.pipe descriptors, as seen with https://github.com/tornadoweb/tornado/blob/master/tornado/platform/posix.py#L37

(FWIW, this is motivated by attempting to run the Tornado test suite, which is further motivated by the Tornado benchmark that Jython does not yet run, see Brett Cannon's notebook on Python performance, http://nbviewer.jupyter.org/gist/brettcannon/9d19cc184ea45b3e7ca0)
msg10670 (view) Author: Jim Baker (zyasoft) Date: 2016-01-26.21:20:57
Also used in the package youtube-dl for file locking support:

    import fcntl

    def _lock_file(f, exclusive):
        fcntl.flock(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)

    def _unlock_file(f):
        fcntl.flock(f, fcntl.LOCK_UN)

This specific functionality is implementable with https://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileLock.html, which is likely to be portable than JNR for this particular support (based on previous experience - use JNR only when nothing else is available in Java).
msg10886 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2016-08-01.03:53:07
Note that fcntl is workable with JyNI, at least to some extend on Linux (didn't try on OSX yet). I did not test in detail, but I know that it is sufficiently supported to allow numpy-import to succeed. I didn't investigate what numpy actually does with fcntl, but if I let JyNI log imported modules, it lists fcntl when importing numpy.
History
Date User Action Args
2018-03-07 19:14:17jeff.allensetmilestone: Jython 2.7.2 ->
2016-08-01 03:53:09stefan.richthofersetnosy: + stefan.richthofer
messages: + msg10886
2016-01-26 21:20:58zyasoftsetmessages: + msg10670
2015-11-17 16:41:09zyasoftsetmessages: + msg10485
2015-11-17 16:35:30zyasoftsetstatus: closed -> open
nosy: + zyasoft
messages: + msg10484
assignee: fwierzbicki ->
milestone: Jython 2.7.2
resolution: wont fix -> accepted
2013-02-20 00:18:31fwierzbickisetstatus: open -> closed
versions: + Jython 2.7, - 2.7a2
2013-02-20 00:18:21fwierzbickisetpriority: low
assignee: fwierzbicki
resolution: wont fix
messages: + msg7713
nosy: + fwierzbicki
2012-11-07 22:39:06amaksetmessages: + msg7517
2012-08-28 22:22:05amaksetnosy: + amak
2012-07-01 10:30:37wbranacreate