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.

classification
Title: use PyOS_ReadlineFunctionPointer in non-interractive input
Type: enhancement Stage: test needed
Components: Interpreter Core Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, amaury.forgeotdarc, greglielens
Priority: normal Keywords: patch

Created on 2005-11-27 17:34 by greglielens, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
readline.fullpatch greglielens, 2005-11-27 17:34 patch is relative to the current svn repository (modifs in Include/pythonrun.h, Parser/myreadline.c, Modules/readline.c and Python/bltinmodule.c)
Messages (3)
msg49129 - (view) Author: Gregory Lielens (greglielens) Date: 2005-11-27 17:34
Python provide a nice input hook for overiding it's
input mechanism: User can define set
PyOS_ReadlineFunctionPointer to point to an input
function, and this function will be used instead of 
the default input function (PyOS_StdioReadline, or
vms__StdioReadline for VMS).

This mechanism can be very handy when implementing a
parallel python interpreter: the main process can
simply brodcast to listening input functions its own
input strings. However, the current implementation does
not use the hook (PyOS_ReadlineFunctionPointer) when it
detect that the input or output are non-interractive
(non-tty), but instead call directly the default
implementation PyOS_StdioReadline. 
A snippet of "Parser/myreadline.c":

...

if (!isatty (fileno (sys_stdin)) || !isatty (fileno
(sys_stdout)))
rv = PyOS_StdioReadline (sys_stdin, sys_stdout, prompt);
else
rv = (*PyOS_ReadlineFunctionPointer)(sys_stdin, sys_stdout,
prompt);
...

This makes impossible to override the input behavior
for non-interractive input. In particular, this prevent
implementing parallel python interpreter because only
the main python interpreter process have tty
input/output, but even in non-parralel context I feel
this uneccessarily limit the hook mechanism...

I submitted a patch some time ago [id 955928], and
Lisandro Dalcin submitted his own patch [id 1232343]to
solve the same problem in the same context (parallel
python interpreter).

Since then, we collaborated for producing a single
patch, cleaner than the previous ones. We also used
input from the python-dev list
[http://mail.python.org/pipermail/python-dev/2005-August/055761.html]
and from the author of the VMS patch in PyOS_Readline
(Jean-François Piéronne). This new patch thus replace
the 2 precedent ones that should be marked as "duplicate".

This patch passes 'Lib/test/regrtest.py' (of course,
all those tests are non-interactive!). Lisandro and my
company use this patched Python interpreter every day
in the standard way and also in MPI-parallelized
interactive sessions, and we never had any problem.

The patch is relative to the current svn repository,
and implement modification in Include/pythonrun.h,
Parser/myreadline.c, Modules/readline.c and
Python/bltinmodule.c. 

This last modification is needed for correcting the
current behavior (not use the hook for non-interractive
input/output) for the raw_input builtin. It is not
needed for using the standard python interractive mode,
but is needed if one want to use the ipython
interpreter (or any interpreter implementing the input
loop in python itself).
msg83889 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-03-20 23:32
The snippet from "Parser/myreadline.c" is still present in trunk.
msg89938 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-06-30 16:23
Isn't the same functionality already implemented by code.interact()?
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42627
2010-04-29 17:58:34terry.reedysetstatus: pending -> closed
2009-06-30 16:23:55amaury.forgeotdarcsetstatus: open -> pending

nosy: + amaury.forgeotdarc
messages: + msg89938

resolution: rejected
2009-03-20 23:32:21ajaksu2setversions: + Python 3.1, Python 2.7, - Python 2.5
type: enhancement

nosy: + ajaksu2
title: use PyOS_ReadlineFunctionPointer in non-interractive input -> use PyOS_ReadlineFunctionPointer in non-interractive input
messages: + msg83889
stage: test needed
2005-11-27 17:34:31greglielenscreate