Filter
Exclude
Time range
-
Near
🐍 Python Term of the Day: GeneratorExit (Python’s Built-in Exceptions) Occurs when a generator or coroutine is closed. realpython.com/ref/builtin-e…
1
1
11
1,260
(Sorry actually StopIteration, not GeneratorExit)
2
40
Replying to @Lucretiel
You do. In general I think this is a very dumb feature because it only exists to make old coroutines work. Return with a value in a generator has no business as it's an alias for raise GeneratorExit with the return value as value.
3
3
516
Replying to @samuelcolvin
enter after exit <class 'GeneratorExit'> Only `yield 1` is executed, `yield 2` is not. Thus, the context exits when the generator is destroyed and `g.__del__` called (which is a wrapper of `g.close`). See peps.python.org/pep-0342/ and try following code snippets:
3
519
Replying to @haxor @dudexnyc
coroutines still get a GeneratorExit at GC time
1
63
11 Nov 2023
I'm not sure if that's right! Uncaught GeneratorExit exceptions are happening all the time. And that's fine.
1
344
🐍 Python's exception hierarchy is a beautifully designed system, a dance of errors and their graceful handling! - MUST KNOW for application building🐍 👉 Simply put - BaseException -> Exception -> ArithmeticError -> ZeroDivisionError --------- 👉 The Hierarchical Design of Python's Exceptions: In Python, exceptions form a hierarchy, which is essential for a couple of reasons: 1. **Semantic Grouping**: Grouping related exceptions under a common parent exception allows for better organization and understanding of the nature of the exception. 2. **Graceful Exception Handling**: A hierarchical structure allows for catching exceptions at various levels of specificity. 👉 Dissecting the Provided Hierarchy: 1. **`BaseException`**: - At the very root of the exception hierarchy sits the `BaseException` class. It's the base class for all built-in exceptions in Python. - This class is deliberately broad. A few exceptions (like `SystemExit`, `KeyboardInterrupt`, and `GeneratorExit`) derive directly from it, but these are exceptions that are generally outside the regular flow of a program. They usually signal something more "systemic" or external in nature. - It's generally not recommended to catch `BaseException` directly unless you really know what you're doing, because this would catch the aforementioned systemic exceptions as well. 2. **`Exception`**: - This is the next level down and is the base class for almost all user-defined exceptions and many built-in ones. When you're handling exceptions in typical Python code, you're mostly dealing with exceptions derived from this class. - Catching `Exception` will usually avoid stopping your program for things like a user-initiated termination (`KeyboardInterrupt`). 3. **`ArithmeticError`**: - This is a subclass of `Exception` and acts as a catch-all base class for exceptions that occur for various arithmetic errors. - It has a few children, such as `OverflowError`, `FloatingPointError`, and, of course, `ZeroDivisionError`. 4. **`ZeroDivisionError`**: - This is one of the specific exceptions that derives from `ArithmeticError`. It's raised when a division or modulo operation has a denominator of zero. - It's a concrete exception, meaning it's directly instantiable and can be raised by the interpreter. 👉 Practical Implications: Because of this hierarchy, you can craft exception handling blocks (`try-except`) to be as broad or specific as you want. For example: - If you want to catch just division by zero errors, you'd catch `ZeroDivisionError`. - If you want to catch any arithmetic related error, you'd catch `ArithmeticError`. - If you're not sure about the nature of potential exceptions but want to handle almost anything a block of code could raise (with some exceptions, pun intended), you'd catch `Exception`. In essence, Python's exception hierarchy is a beautifully designed system, which, when understood and utilized properly, provides developers with granular control over error handling in their applications. This design ensures code robustness while also preserving the semantic meaning behind each exception type. ------------------ 👉 If you enjoyed this explanation: ✅1. Checkout my recent Python book, covering 130 Python Core concepts like this across 350 pages and detail analysis 📌 Book Link in my Twitter Bio ✅2. Give me a follow @rohanpaul_ai Like & Retweet this tweet ------------ #python #100daysofcode #softwareengineer #programming #coding #programmer #developer #coder #code #computerscience #technology #pythonprogramming #software #webdevelopment #webdeveloper #tech #codinglife #algorithms #algorithm #datastructures #programmers #analytics #leetcode #MachineLearning #ArtificialIntelligence #datascience #nlp #100daysofmlcode #nlp #textprocessing #programminglife #hacking #learntocode #softwaredeveloper #interview
1
5
642
🐍 Python's exception hierarchy is a beautifully designed system, a dance of errors and their graceful handling! - MUST KNOW for serious application building🐍 👉 Simply put - BaseException -> Exception -> ArithmeticError -> ZeroDivisionError --------- ### The Hierarchical Design of Python's Exceptions: In Python, exceptions form a hierarchy, which is essential for a couple of reasons: 1. **Semantic Grouping**: Grouping related exceptions under a common parent exception allows for better organization and understanding of the nature of the exception. 2. **Graceful Exception Handling**: A hierarchical structure allows for catching exceptions at various levels of specificity. ### Dissecting the Provided Hierarchy: 1. **`BaseException`**: - At the very root of the exception hierarchy sits the `BaseException` class. It's the base class for all built-in exceptions in Python. - This class is deliberately broad. A few exceptions (like `SystemExit`, `KeyboardInterrupt`, and `GeneratorExit`) derive directly from it, but these are exceptions that are generally outside the regular flow of a program. They usually signal something more "systemic" or external in nature. - It's generally not recommended to catch `BaseException` directly unless you really know what you're doing, because this would catch the aforementioned systemic exceptions as well. 2. **`Exception`**: - This is the next level down and is the base class for almost all user-defined exceptions and many built-in ones. When you're handling exceptions in typical Python code, you're mostly dealing with exceptions derived from this class. - Catching `Exception` will usually avoid stopping your program for things like a user-initiated termination (`KeyboardInterrupt`). 3. **`ArithmeticError`**: - This is a subclass of `Exception` and acts as a catch-all base class for exceptions that occur for various arithmetic errors. - It has a few children, such as `OverflowError`, `FloatingPointError`, and, of course, `ZeroDivisionError`. 4. **`ZeroDivisionError`**: - This is one of the specific exceptions that derives from `ArithmeticError`. It's raised when a division or modulo operation has a denominator of zero. - It's a concrete exception, meaning it's directly instantiable and can be raised by the interpreter. ### Practical Implications: Because of this hierarchy, you can craft exception handling blocks (`try-except`) to be as broad or specific as you want. For example: - If you want to catch just division by zero errors, you'd catch `ZeroDivisionError`. - If you want to catch any arithmetic related error, you'd catch `ArithmeticError`. - If you're not sure about the nature of potential exceptions but want to handle almost anything a block of code could raise (with some exceptions, pun intended), you'd catch `Exception`. In essence, Python's exception hierarchy is a beautifully designed system, which, when understood and utilized properly, provides developers with granular control over error handling in their applications. This design ensures code robustness while also preserving the semantic meaning behind each exception type. ------------------ 👉 If you enjoyed this explanation: ✅1. Give me a follow @rohanpaul_ai Like & Retweet this tweet ✅2. Also checkout my recent Python book, covering over 100 Python Core concepts across 300 pages, with associated questions, most commonly asked in Interviews, 🐍 rohanpaul.gumroad.com/l/pyth… ------------ #python #100daysofcode #softwareengineer #programming #coding #programmer #developer #coder #code #computerscience #technology #pythonprogramming #software #webdevelopment #webdeveloper #tech #codinglife #algorithms #algorithm #datastructures #programmers #analytics #leetcode #MachineLearning #ArtificialIntelligence #datascience #nlp #100daysofmlcode #nlp #textprocessing #programminglife #hacking #learntocode #softwaredeveloper #interview
1
5
708
Не будем вдаваться в причины, но если код, с которым ты работаешь, порожден больной фантазией маньяка, которого боялся бы сам Сталин, то иногда в твоих корутинах будет генериться Runtime Error, вещающий, что специальный питонячий Exception - GeneratorExit, был проигнорирован.
1
9
2,315
25 Feb 2023
マジで久々にpythonを触ってるんですが、asyncioではまってて草 websocketsのserveしてるcoroutineが「RuntimeError: coroutine ignored GeneratorExit」で死ぬw
1
11
3,936
💥 GeneratorExit: this usually occurs when a generator closes ❎, usually when it finishes producing values or intentionally closed when a close method is called.
1
2
Did you Know python 🐍 defines only four primary BaseException classes: ✔ SystemExit ✔ KeyboardInterrupt ✔ GeneratorExit ✔ Exception Let's get to understand them in this thread
1
2
yieldの値を返した先でbreakするとエラーログが残ってた。原因はジェネレータを閉じた際のclose()によって例外GeneratorExitが発生するからであり、厳密にいうとエラーではないみたい。なんじゃそら(*'ω'*) #Python
1
9 Nov 2021
Replying to @__pity_ @raymondh
I'm not sure, but I think he means generator.throw(GeneratorExit)
1
3
#Python factlet: Calling the close() method on a generator is equivalent to calling throw(GeneratorExit) and then verifying that the generator actually terminates, either with a GeneratorExit or a StopIteration exception.
3
8
48
A contextmanager won't work; you can't yield twice. This won't work either: def ensure_model(model_name): try: yield except (IOError, GeneratorExit): download_model(model_name) yield You can't `yield` after GeneratorExit. Is it impossible? I really want it.
1
2
23 Oct 2018
Muizz is going through a GeneratorExit
1
1
22 Jun 2018
GeneratorExit - How to clean up after the last yield in #Python dtr.ee/2lk3oqv
3
3
PyCharm #protip: set this condition for "Any exception" breakpoint and it won't break for StopIteration/GeneratorExit.
3
21
3 May 2016
Generator終了時のGeneratorExitはException配下でないので、except Exceptionでは捕捉できずexceptで捕捉されるのでこの差異が出ると思われ docs.python.org/3.5/library/… x.com/odashi_t/status/727478…

2
1