473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Displaying print messages- Emacs

I am using Emacs Python mode, and my project involves reading large
datafiles and processing large arrays. I have some code that reports the
progress during these time consuming processes. It works fine from the
dos shell, but I would really like to work entirely within Emacs. I have
two questions:

1) Is it possible to have the *Python Output* in Emacs report the
progress during execution? Right now, *Python Output* does not update
until after the script completes.

2) If #1 is possible, can I simulate a progress bar using some character
and '\b'? This works in the dos shell, but the Emacs ouput interprets
'\b' to print '^H' rather than a backspace. (Why does it do that?)

Thank you,
Darren
Jul 18 '05 #1
5 2294
Hi Darren - not sure about the second question, but I might have an answer
for the first...

In article <ce**********@news01.cit.cornell.edu>, Darren Dale wrote:
1) Is it possible to have the *Python Output* in Emacs report the
progress during execution? Right now, *Python Output* does not update
until after the script completes.


Try using sys.stdout.flush() at regular intervals in your code. I've had
similar problems using Python+Emacs+Cygwin, and flushing the output buffer
usually solved the problem.

--
.:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.

"When the country is confused and in chaos, information scientists appear."
Librarian's Lao Tzu: http://www.geocities.com/onelibrarian.geo/lao_tzu.html
Jul 18 '05 #2
Dave Benjamin <ra***@lackingtalent.com> writes:
Hi Darren - not sure about the second question, but I might have an answer
for the first...

In article <ce**********@news01.cit.cornell.edu>, Darren Dale wrote:
1) Is it possible to have the *Python Output* in Emacs report the
progress during execution? Right now, *Python Output* does not update
until after the script completes.


Try using sys.stdout.flush() at regular intervals in your code. I've had
similar problems using Python+Emacs+Cygwin, and flushing the output buffer
usually solved the problem.


Or just start Python with -u (unbuffered) or -i (interactive) from
within the shell. Avoids the need to change the script.

The root cause is probably that Emacs' shell is not considered a TTY,
so it gets buffered output by default.

-- David
Jul 18 '05 #3
>
The root cause is probably that Emacs' shell is not considered a TTY,
so it gets buffered output by default.


What is TTY?
Jul 18 '05 #4
>
Or just start Python with -u (unbuffered) or -i (interactive) from
within the shell. Avoids the need to change the script.


I forgot to ask, how would I do this from Emacs?
Jul 18 '05 #5
Darren Dale <dd**@cornell.edu> writes:

Or just start Python with -u (unbuffered) or -i (interactive) from
within the shell. Avoids the need to change the script.


I forgot to ask, how would I do this from Emacs?


Well, let's assume that you're at the shell prompt from inside Emacs
(how you got there could depend on your Emacs setup, whether M-x shell
or some keystrokes). Then, instead of doing something like:

(shell prompt) python yourscript.py

do

(shell prompt) python -u yourscript.py

It'll run your script just as before but forceably disabling any
output buffering, which it would otherwise enable automatically when
detecting that its output did not appear to be a interactive (a TTY).
You should see anything produced by your script in the Emacs buffer as
soon as the script generates it.

To answer your other question, short answer is that saying "is a tty"
is more or less a shorthand for saying whether the output is being
displayed to a user on an interactive device.

Longer answer is that historically TTY was a teletypewriter (and still
can mean that in the context of hearing impaired phone devices today),
the idea being that a keyboard and display was used for communication.
Over time, and particular with it's use in Unix systems, it's come to
encompass the general idea of a terminal I/O device. More
specifically it is common (in the Unix world) to use the term TTY to
refer to an actual physical output device as opposed to other devices
like pipes, files, network sockets, etc...

So saying that output "appears to be a TTY" is a shorthand way of
saying that the output device appears to be a true interactive display
device rather than output being redirected to a file or other
connection. There's even a (fairly portable) C library routine called
"isatty" (is a tty) that Python uses to determine this. It's not
uncommon for an application (generally through default behavior of the
platform C library) to adjust buffering based on that status, so as to
be more efficient in the non-TTY case where interactive latency of
display is not as important as utilizing the bandwidth to the output
device most effectively.

Generally speaking, when one process opens a pipe or otherwise
controls another process, it won't appear to be a TTY to the other
process, since that process' output is going through some system
object (for example, a pipe). There are packages that in fact exist
soley to simulate TTYs (or provide PTTYs, Pseudo-TTYs) to better
simulate a user running an application, such as Expect.

Anyway, when Emacs is running the child shell, it executes that shell
as a child process for which it controls the I/O, but the connection
between Emacs and that child process is not perceived as a TTY by the
system, and thus nor by Python, so it permits more efficient buffering
to take place. Unfortunately, that more efficient buffering is not
what you want when you are working with something interatively.

Using the -u command line option tells Python to disable all output
buffering regardless of the TTY status of it's output. This is
actually even less efficient than the default TTY state (which is
typically line buffered) but it ensures you'll see everything on the
output as soon as it is generated. You can also get the same effect
by having the PYTHONUNBUFFERED environment variable set when you start
python.

-- David
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wayne Pierce | last post by:
I have a small script with PHP that queries a MySQL database to pull out one row, where I want to be able to access each of the columns separately. I have tried several different variations and am...
4
by: James | last post by:
Hello All, I have a stored procedure which will act like a main/controller script which will then invoke more stored procedures (~20). Basically, it looks something like below: -- start...
1
by: Mark ??;-\) | last post by:
I would like to display a listing of files on a web page as follows: If there is only one file: display the section name and then display the current file. If there is more than one file (for...
5
by: Robert | last post by:
Hello Accessors I have some reports created in Access that are very good for what they do. However, it seems to me that when you are displaying information you don't need to print out that a...
0
by: Paul | last post by:
Occasionally my users will try to perform an action and be presented with an exception raised directly from SQL Server, in example: SET @err = 'a user-friendly error condition message'...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
7
by: swethasivaram | last post by:
Hello I have a Java-based web application whose interface can be in multiple languages. My requirement is that the javascript alerts that I display should be displayed in the language in which...
2
by: Bill_DBA | last post by:
I have the following stored procedure that is called from the source of a transformation in a DTS package. The first parameter turns on PRINT debug messages. The second, when equals 1, turns on the...
13
by: David W. Fenton | last post by:
I've been struggling the last two days with something I thought was very easy, which is to open a web page with a form on it and populate the form with data passed in a query string (either POST or...
3
by: davidiwharper | last post by:
Hello everyone, I'm learning Perl again! I am writing a CGI script that has two possible outcomes. So I have broken up the HTML output into four parts: Beginning (header and the start of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.