Hi all, I am new to textmate and Java/Python programming. When I run my code with the textmate run command, there seems to be a problem with the order of output in html. This problem seems not to be bundle specific (both Java and Python bundle show the same problem) so I guess it is in the underlying executor script. The bundles and support dir are fresh SVN checkouts.
Example code: guess.py
import random
secret = random.randint(1, 99) guess = 0 i = 0
while guess != secret: guess = input("Make a guess (0 to quit): ") if guess == 0: print "Program quit" break elif guess > secret: print "to big" elif guess < secret: print "to small" i = i + 1 else: print "Congratulations, you guessed right after",i ,"tries." Example output: order is: prompt -> program output -> input Make a guess (0 to quit): to small 1 Make a guess (0 to quit): to small 2 Make a guess (0 to quit): to small 3 Make a guess (0 to quit): to small 4 Make a guess (0 to quit): Output order should be: prompt -> input -> program output I'd like to use textmate in my cs cources starting soon and it would be great if the html output had the right order, so I can hand it out to the teacher as a proof for my working code. At the moment this would be rather confusing and lead to some discussions I guess.
On 02/04/2009, at 5:50 PM, Sebastian Röder wrote:
I am new to textmate and Java/Python programming. When I run my code with the textmate run command, there seems to be a problem with the order of output in html. This problem seems not to be bundle specific (both Java and Python bundle show the same problem) so I guess it is in the underlying executor script. The bundles and support dir are fresh SVN checkouts.
Example code: guess.py
import random
secret = random.randint(1, 99) guess = 0 i = 0
while guess != secret: guess = input("Make a guess (0 to quit): ") if guess == 0: print "Program quit" break elif guess > secret: print "to big" elif guess < secret: print "to small" i = i + 1 else: print "Congratulations, you guessed right after",i ,"tries." Example output: order is: prompt -> program output -> input Make a guess (0 to quit): to small 1 Make a guess (0 to quit): to small 2 Make a guess (0 to quit): to small 3 Make a guess (0 to quit): to small 4 Make a guess (0 to quit): Output order should be: prompt -> input -> program output I'd like to use textmate in my cs cources starting soon and it would be great if the html output had the right order, so I can hand it out to the teacher as a proof for my working code. At the moment this would be rather confusing and lead to some discussions I guess.
I checked this out in the Python case and as expected it's due to Python buffering the output.
What's interesting though is that the Python “Run” command sets the -u flag when invoking python which should disable buffering. I also tried setting the PYTHONUNBUFFERED env var and that didn't work either.
However if I added…
import os import sys sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
to the script then the output was as it should be. So the question is why is Python ignoring -u and PYTHONUNBUFFERED?
@Sebastian » you should be using ‘too’ instead of ‘to’ here (e.g. too small/big)
On Apr 2, 2009, at 5:10 PM, Luke Daley wrote:
What's interesting though is that the Python “Run” command sets the -u flag when invoking python which should disable buffering. I also tried setting the PYTHONUNBUFFERED env var and that didn't work either.
What's even more interesting is that this definitely *did* work at one point. Does it (un)buffer properly with TM_INTERACTIVE_INPUT_DISABLED? You'll have to use a different example than input to test it…
—Alex