Python API enables the Asyncio debug mode by default without providing a way to disable it.
- iTerm2 version: 3.3.0beta6
- OS version: 10.14.4 (18E226)
Detailed steps to reproduce the problem:
- Create an app using the iTerm2 Python API and use the
- Perform various tasks through the app and eventually you will see messages like the ones below being printed to stderr.
Executing <Handle <TaskWakeupMethWrapper object at 0x1030a3d98>(<Future finis...ection.py:224>) created at /Users/rickygrassmuck/Library/Caches/pypoetry/virtualenvs/it2-autossh-py3.7/lib/python3.7/site-packages/iterm2/connection.py:118> took 0.505 seconds
What happened: From connection.py:
179 # This keeps you from pulling your hair out. The downside is uncertain, but 180 # I do know that pulling my hair out hurts. 181 loop.set_debug(True) 182 self.loop = loop
Connection().run() method is enabling the Asyncio debug mode which results in the printing of various messages like the one above. While useful when actually trying to debug a script or when working on the library itself, they can quickly become clutter when the debug output is no longer needed.
What should have happened: There should be a mechanism for disabling debug mode available to the end user.
Below is a patch to the connection.py module that provides the option to add
debug=(True|False) when invoking the
run_forever() methods to give the end users the ability to set this option themselves. The patch is just an example but its worth noting that it would not break these methods for existing scripts/apps using them.
I can open a pull request on Github with these changes if desired as well(More than willing to go a different route with the implementation if the method below isn't ideal).
diff --git a/api/library/python/iterm2/iterm2/connection.py b/api/library/python/iterm2/iterm2/connection.py index dbcd2b4df..6833083fe 100644 --- a/api/library/python/iterm2/iterm2/connection.py +++ b/api/library/python/iterm2/iterm2/connection.py @@ -101,11 +101,17 @@ class Connection: don't need to any more.""" self.__tasks = list(filter(lambda t: not t.done(), self.__tasks)) - def run_until_complete(self, coro, retry): - self.run(False, coro, retry) - - def run_forever(self, coro, retry): - self.run(True, coro, retry) + def run_until_complete(self, coro, retry, **kwargs): + debug = True + if 'debug' in kwargs: + debug = kwargs['debug'] + self.run(False, coro, retry, debug) + + def run_forever(self, coro, retry, **kwargs): + debug = True + if 'debug' in kwargs: + debug = kwargs['debug'] + self.run(True, coro, retry, debug) def set_message_in_future(self, loop, message, future): assert future is not None @@ -145,7 +151,7 @@ class Connection: traceback.print_exc() raise - def run(self, forever, coro, retry): + def run(self, forever, coro, retry, debug=True): """ Convenience method to start a program. @@ -172,7 +178,7 @@ class Connection: # This keeps you from pulling your hair out. The downside is uncertain, but # I do know that pulling my hair out hurts. - loop.set_debug(True) + loop.set_debug(debug) self.loop = loop loop.run_until_complete(self.async_connect(async_main, retry))