[issue25489] sys.exit() caught in exception handler

2015-10-30 Thread Brian Sutherland

Brian Sutherland added the comment:

On Wed, Oct 28, 2015 at 03:32:36PM +, Guido van Rossum wrote:
> 
> Guido van Rossum added the comment:
> 
> How about we extend loop.stop() so that you can pass it an exception to
> raise once the loop is stopped? This exception would then be thrown out of
> run_forever(). There may be some delay (callbacks already scheduled will
> run first) but it is how things were meant to be.

It is better than the current situation where to call loop.stop() and
have the correct exit code I would need to resort to a global variable.

I would then probably try to write an exception handler like this:

def exception_handler(loop, context):
loop.stop(context.get('exception', Exception('unknown error')))

And then hope I don't lose the traceback!

> FWIW this isn't really enough to ensure cleanup happens before destructors
> run -- when the loop exits, tasks may still be active unless you keep track
> of all of them and explicitly cancel them (and run the loop until they have
> processed the cancellation).

At least in my situation I don't think this is a problem, the objective
is to shut down the process quickly to prevent bad things happening.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25489>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25489] sys.exit() caught in exception handler

2015-10-29 Thread Brian Sutherland

Brian Sutherland added the comment:

On Wed, Oct 28, 2015 at 02:49:55PM +, R. David Murray wrote:
> 
> R. David Murray added the comment:
> 
> Using sys.exit means you are depending on garbage collection to clean
> up all of your program's resources.  In the general case this is a bad
> idea.  A better design is to call loop.stop, and then do cleanup
> (which might involve calling some wait_closed functions via
> loop.run_until_complete).  If you just call sys.exit, your resources
> may not get cleaned up correctly, or may not get cleaned up correctly
> somewhat randomly due to the indeterminacies in the order in which
> garbage collection is done.  This may not matter for a simple program,
> but I find it makes it easier for me if I just do it "the right way"
> always :)

I think it depends on the problem, sometimes "crash-only" software is
safer. You have to design for immediate failure anyway, can't stop those
pesky hardware failures. So if you always immediately crash there is
only one, well-tested path to stopping a program.

Also saves a lot of cleanup code writing;)

Hmm, I suppose that means I should really be using os._exit(42) to avoid
garbage collection...

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25489>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25489] sys.exit() caught in exception handler

2015-10-28 Thread Brian Sutherland

Brian Sutherland added the comment:

Calling loop.stop() means that I need other, more complex code, to store and 
return the non-zero exit status.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25489>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25489] sys.exit() caught in exception handler

2015-10-27 Thread Brian Sutherland

New submission from Brian Sutherland:

Running the attached file with python3 shows that SystemExit is caught rather 
than causing the process to stop. That's quite surprising.

--
components: asyncio
files: test_sys_exit_in_exception_handler.py
messages: 253529
nosy: gvanrossum, haypo, jinty, yselivanov
priority: normal
severity: normal
status: open
title: sys.exit() caught in exception handler
versions: Python 3.5
Added file: 
http://bugs.python.org/file40867/test_sys_exit_in_exception_handler.py

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25489>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25489] sys.exit() caught in exception handler

2015-10-27 Thread Brian Sutherland

Brian Sutherland added the comment:

the workaround I am using at the moment is this:

def handler(loop, context):
print('Got error, exiting')
loop.call_soon(sys.exit, 42)

which actually does cause the process to exit

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25489>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16981] ImportError hides real error when there too many open files during an import

2013-01-16 Thread Brian Sutherland

New submission from Brian Sutherland:

When running Python inside PostgreSQL using plpython on OSX 10.7.5 I started 
coming across very strange and apparently random ImportErrors. For example, 
failing to find the stat module while importing site:

 Traceback (most recent call last):
   File /Users/jinty/.buildout/eggs/setuptools-0.6c11-py2.7.egg/site.py, 
line 73, in module
 __boot()
   File /Users/jinty/.buildout/eggs/setuptools-0.6c11-py2.7.egg/site.py, 
line 2, in __boot
 import sys, imp, os, os.path
   File /Users/jinty/src/mp/lib/python2.7/os.py, line 49, in module
 import posixpath as path
   File /Users/jinty/src/mp/lib/python2.7/posixpath.py, line 15, in 
module
 import stat
 ImportError: No module named stat

I debugged this by using PYTHONVERBOSE and modifying import.c with the attached 
patch. I found that stat.py was not found because fopen() failed with Too many 
open files. There were not enough open files because OSX has insanely low 
limits and PostgreSQL was using a large chunk of that. ulimit -n 4096 resolved 
the errors. I spent a LOT of time trying to figure that out (see the thread at 
http://www.postgresql.org/message-id/20130114163014.GA600@Brians-MacBook-Air.local).

The bug I wish to report is that the real error (Too many open files) is hidden 
by ImportError: No module named stat. For anyone who does not want to modify 
import.c and rebuild python, it is almost impossible to figure out what is 
really happening.

--
files: patch-Python-import.c.diff
keywords: patch
messages: 180092
nosy: jinty
priority: normal
severity: normal
status: open
title: ImportError hides real error when there too many open files during an 
import
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file28753/patch-Python-import.c.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16981
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Making a calendar

2005-02-26 Thread Brian Sutherland
On Sat, Feb 26, 2005 at 01:57:20PM +0100, Pete. wrote:
 I'm trying to make a calendar for my webpage, python and html is the only 
 programming languages that I know, is it possible to make such a calendar 
 with pythong code and some html.
 
 The Idea is that when I click the link calendar on my webpage, then the user 
 will be linked to the calendar.
 
 The calendar should show one month at the time, and the user should be able 
 to browse to the other month.
 
 I will make a script that puts events and such into a db ( I know how to do 
 this)
 
 Then I need a script that puts the events from the db into the calendar, if 
 every day in the calendar has a value id that part will not be hard.

All this and more (perhaps overkill):

http://www.schooltool.org/schoolbell

-- 
Brian Sutherland

It's 10 minutes, 5 if you walk fast.
-- 
http://mail.python.org/mailman/listinfo/python-list