473,763 Members | 7,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2308
Hi Darren - not sure about the second question, but I might have an answer
for the first...

In article <ce**********@n ews01.cit.corne ll.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.flus h() at regular intervals in your code. I've had
similar problems using Python+Emacs+Cy gwin, 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***@lackingt alent.com> writes:
Hi Darren - not sure about the second question, but I might have an answer
for the first...

In article <ce**********@n ews01.cit.corne ll.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.flus h() at regular intervals in your code. I've had
similar problems using Python+Emacs+Cy gwin, 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.e du> 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 PYTHONUNBUFFERE D 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
3498
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 able to get the entire row to print, but when I attempt to access the individual columns I get an error. Here is what I have so far: if (isset($_POST)): $link = mysql_connect('...','...','...'); mysql_select_db("...");
4
14790
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 script create procedure ... print 'process started' exec sp_1
1
1964
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 the first page): display the section name, the current file and a few archive files. If there is more than a page full (for each additional page): display the section name, and the next set of archive files.
5
2226
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 printer-friendly report is not the best way to go. So, I tried converting one of my Access reports to an Access form. I selected the continuous view to allow displaying multple records but when I went to define my sorting and grouping there was none...
0
1448
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' RAISERROR(@err, 16, 1, 1) RETURN The exception type thrown is a System.Data.SqlClient.SqlException, and its message property holds the exception text. Works well for the most part. However, a lot of times the SQL error conditions happen after a trigger...
1
5720
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 of a Microsoft book, "Visual Basic,Net Step by Step" in Chapter 18. All but the bottom two subroutines will open a text file, and then allow me to use the above controls, example 1. The bottom two subroutines will print a graphic file, example...
7
8360
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 the interface has been generated. The interface language is dynamically loaded and the text is displayed using Java's <fmttags. How can I make the Javascript alerts, etc. also change their display language dynamically? Is it possible in...
2
22880
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 openning, fetching, and closing of a cursor. Things are fine if only one of the two parameters was set to 1. When run with both parameters turned on, "dba_test_dts 1, 1", DTS source (tab) preview fails because it thinks no row was returned....
13
2900
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 GET). I got Application.FollowHyperlink *kind* of working, but was having problem with double encoding of some characters (I had to do special things with + signs in the data, as well as never figuring out why some data was getting...
3
1366
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 HTML) Option 1 OR Option 2
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.