[Tutor] Best way to use excepthook here?

Alan Gauld alan.gauld at yahoo.co.uk
Thu Jun 23 19:51:38 EDT 2016


On 23/06/16 22:08, Alex Hall wrote:

> setup I'm going to try first is one file per job, with utils.py and a
> couple others shared between them all. 
> ...
> Now, Python is running two scripts which each have their excepthook set to
> something different. What happens when both try to log an exception, 

They both do their own thing because you have two entirely separate
instances of the interpreter running, each in its own process. So they
both set their own excepthook and is none the wiser of what the other
one is doing.

If you later decide to bring the jobs into a single program, maybe
running each job in a separate thread then things get more tricky.
But if you run each job as a separate script then there is no
issue (unless they are both sharing a file/database but that's
a standard OS locking type issue, nothing specific to Python.

> or will there be confusion? Should I thread it somehow? 

Threading will make it much more complex. Better to keep separate
processes unless there are so many your server runs out of
resources...

> worrying over nothing, or will I need to do something to make sure each job
> logs exceptions, and does it correctly, no matter who else is running at
> the same time? Thanks.

I think you should be fine provided you log into separate
files per job and are not trying to modify the same data in the
database. But these are standard batch processing concerns,
easiest solved by designing the job schedule to avoid conflicts.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list