"Since python integers can be of arbitrary size, you can easily cause calculations that will take a long time, such as raising an integer to a big power. I've only used hcpy under cygwin on Windows; I've found that a ctrl-C is needed to stop these long calculations. Unfortunately, this leads to an immediate exit from the program and the operands will be lost and current settings will not persist. If someone knows of a platform-independent way of interrupting processing in python, please submit an enhancement request on the issues tab."
Pressing ctrl-c (or any equivalent) raises a KeyboardInterrupt you can catch:
>>> def f(): ... try: ... while 1: pass ... except KeyboardInterrupt: ... print "interrupted" ... >>> f() ^Cinterrupted >>>
This way, I think you can make sure that nothing gets lost.
BTW, your calculator is a great application! I'm not used to RPN (guess it's more effective than the ordinary syntax if you got used to), so I can hardly use it, but the number formatting is definitely superior to mpmath's. I think this should be ported.
Comment #1
Posted on Feb 6, 2009 by Helpful CatWell, dang, I coulda sworn I tried every exception in the list, including this one. But it works like a charm. Thanks!
Those of us who went to college in the 60's and wanted to use the first calculators kinda had to learn to use the HP RPN syntax. I had a few TI calculators too, but never liked the algebraic syntax.
Putting RPN and algebraic weenies in a room is almost as much fun as putting vi centipedes and emacs scorpions in a bottle and shaking it... :^)
Comment #2
Posted on Feb 7, 2009 by Helpful CatArgh! I had the keyboard exception catcher after an 'except Exception' clause -- I saw the problem as soon as I saw the code. I tried a simple app with the keyboard catcher and it works great. But in my app, it still doesn't work -- the program exits even though I can see there are no intervening exception handlers.
Comment #3
Posted on Mar 5, 2009 by Happy LionSo, I was really lazy, and didn't read through all your hc.py, but the following diff:
2244c2244,2251
< cmd_line = GetLineOfInput()
cmd_line = None try: cmd_line = GetLineOfInput() except KeyboardInterrupt, ke: print "caught keyboardinterruption, saving configuration" SaveConfiguration() print "caught keyboardinterruption, exiting" exit( 1 )
accomplishes: % python hc.py
1 x: 1 2 y: 1 x: 2 +^Ccaught keyboardinterruption, saving configuration caught keyboardinterruption, exiting %
Comment #4
Posted on Mar 17, 2009 by Helpful CatThanks; that works now, yet it didn't before. I've since gone through a reformat of the hard drive and re-installation of the hated Windows OS (it had corrupted itself and was unable to repair itself). Sigh -- I'd switch back to Linux if I didn't have customers that require the use of Windows...
Comment #5
Posted on Mar 17, 2009 by Helpful Cat(No comment was entered for this change.)
Comment #6
Posted on Mar 17, 2009 by Quick CatDual boot? :)
Status: Fixed
Labels:
Type-Defect
Priority-Medium