Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateNotCalled as a singleton may not be a good idea #4

Closed
jamadden opened this issue Oct 16, 2017 · 3 comments
Closed

UpdateNotCalled as a singleton may not be a good idea #4

jamadden opened this issue Oct 16, 2017 · 3 comments

Comments

@jamadden
Copy link
Member

Because on Python 3, exceptions are stateful. They store their traceback indefinitely. So there are two potential problems: (1) thread safety and (2) leaks.

In [1]: from zope.contentprovider.interfaces import UpdateNotCalled

In [2]: raise UpdateNotCalled
---------------------------------------------------------------------------
UpdateNotCalled                           Traceback (most recent call last)
<ipython-input-2-ddcbc1dc41ad> in <module>()
----> 1 raise UpdateNotCalled

UpdateNotCalled: ``update()`` was not called yet.

In [3]: UpdateNotCalled.__traceback__
Out[3]: <traceback at 0x10a90af88>

In [4]: UpdateNotCalled.__traceback__.tb_frame.f_locals
Out[4]:
{'code_obj': <code object <module> at 0x10a5a6c00, file "<ipython-input-2-ddcbc1dc41ad>", line 1>,
 'old_excepthook': <bound method BaseIPythonApplication.excepthook of <IPython.terminal.ipapp.TerminalIPythonApp object at 0x10809ac88>>,
 'outflag': True,
 'result': <ExecutionResult object at 10a531a58, execution_count=2 error_before_exec=None error_in_exec=``update()`` was not called yet. result=None>,
 'self': <IPython.terminal.interactiveshell.TerminalInteractiveShell at 0x10a347ef0>}
@mgedmin
Copy link
Member

mgedmin commented Oct 17, 2017

Whoa. Does Python even allow you to write except: ExceptionInstance:???

@mgedmin
Copy link
Member

mgedmin commented Oct 17, 2017

Yeah, this doesn't work (exception is never caught) on Python 2 and is not allowed on Python 3:

TypeError: catching classes that do not inherit from BaseException is not allowed

@jamadden
Copy link
Member Author

Yeah, you'd have to except RuntimeError or except Exception to catch it.

To be fair, no code in zopefoundation seems to raise it. It's documented as optional for implementations of content providers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants