function
def _copying(self):
result = self.result.toPlainText().strip().split('\n')
to_copy = '\n'.join(result)
pyperclip.copy(to_copy)
in the MainWindow()
of my PyQt5 project raises an exception "StopIteration" in contextlib.py _GeneratorContextManager()
, line 119 'next(self.gen)'
.
result
is a ui.TextEdit
object. Could u please tell me what does it mean?
Google says i should wrap my func into with-construction, but i don't really inderstand how, and don't sure it's a good idea.
Debugger says:
__exception__ = {tuple} <class 'tuple'>: (<class 'StopIteration'>, StopIteration(), <traceback object at 0x045DA918>)
0 = {type} <class 'StopIteration'>
args = {getset_descriptor} <attribute 'args' of 'BaseException' objects>
value = {member_descriptor} <member 'value' of 'StopIteration' objects>
1 = {StopIteration}
args = {tuple} <class 'tuple'>: ()
value = {NoneType} None
2 = {traceback} <traceback object at 0x045DA918>
tb_frame = {frame} __exit__ [contextlib.py:119] id:54111736
tb_lasti = {int} 16
tb_lineno = {int} 119
tb_next = {NoneType} None
__len__ = {int} 3
Console says nothing. But the project is crashing.
That StopIteration is completely normal and expected. It's part of the normal operation of contextlib.contextmanager
. It's supposed to happen, and it's caught and handled immediately; if it doesn't happen, there's a problem.
I don't know how you've even ended up at the point where you're looking at this exception, considering how it never escapes the contextlib
internals, but if you're blaming it for your code's problems, you're blaming the wrong thing.