"Steven D'Aprano" wrote in message news:5553145b$0$11119$c3e8...@news.astraweb.com...

On Wednesday 13 May 2015 17:27, Christian Gollwitzer wrote:

A clean way to exit your script could be to raise an exception. It
should propagate to the toplevel and halt your script. However it is not
possible to back and resume the execution.

"
while True:
   try:
       run_script()  # May raise TryAgain
       break
   except TryAgain:
       pass


If you prefer to only retry a finite number of times:


for i in range(10):
   try:
       run_script()  # May raise TryAgain
       break
   except TryAgain:
       pass
else:
   # break skips past the for...else block
   raise GiveUpError('too many failures')
"

Hi,

Thanks for the ideas, I haven't tried them yet.

I wonder if they will work in a multi-threaded fashion.

I doubt it.

The run_script runs in it's own thread.

The exception would have to be raise from another thread. (The other thread check for errors and needs to abort the run script).

I doubt thread B can interrupt thread A via exceptions/exception handling ?!?

Bye,
Skybuck.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to