On Fri, 14 Jun 2019 at 11:20, Andrew Svetlov <andrew.svet...@gmail.com> wrote:
> We need either both `asyncio.switch()` and `time.switch()` > (`threading.switch()` maybe) or none of them. > > https://docs.python.org/3/library/asyncio-task.html#sleeping has the > explicit sentence: > > sleep() always suspends the current task, allowing other tasks to run. > Ok, I agree this, or an improved version of this sentence to explicitly illustrate the "sleep(0)" case is enough. > > On Fri, Jun 14, 2019 at 5:06 PM Joao S. O. Bueno <jsbu...@python.org.br> > wrote: > > > > > it is very well known feature. > > > > Or is it? Just because you do know it, it does not mean it is universal - > > This is not documented on time.sleep, threading.Thread, or asyncio.sleep > anyway. > > > > I've never worked much on explicitly multi-threaded code, but in 15+ > years > > this is a pattern I had not seem up to today. > > The original writer of this Thread, Nikita, also does not seem > > to have found `asyncio.sleep(0)` in less than 10 minutes looking > > for what he needed. > > > > It allows for "explcit is better than implicit", and really > > asserts the intention of the code writer, and have > > a low cost to implement in the stdlib. > > > > > > > > And it is semantically more correct at the cost of maybe 3loc on the > stdlib. > > > > On Fri, 14 Jun 2019 at 10:57, Andrew Svetlov <andrew.svet...@gmail.com> > wrote: > >> > >> time.sleep(0) is used for a thread context switch, it is very well > >> known feature. > >> await asyncio.sleep(0) does the same for async tasks. > >> Why do we need another API? > >> > >> On Fri, Jun 14, 2019 at 4:43 PM Joao S. O. Bueno <jsbu...@python.org.br> > wrote: > >> > > >> > Regardless of a mechanism to counting time, and etc... > >> > > >> > Maybe a plain and simple adition to asincio would be a > >> > context-switching call that does what `asyncio.sleep(0)` does today? > >> > > >> > It would feel better to write something like > >> > `await asyncio.switch()` than an arbitrary `sleep`. > >> > > >> > On Fri, 14 Jun 2019 at 10:27, Nikita Melentev < > multisosnoo...@gmail.com> wrote: > >> >> > >> >> Fortunately, asyncio provide this good universal default: 100ms, > when WARING appears. Nested loops can be solved with context manager, which > will share `last_context_switch_time` between loops. But main thing here is > that this is strictly optional, and when someone will use this thing he > will know what it is and why he need this. > >> >> _______________________________________________ > >> >> Python-ideas mailing list -- python-ideas@python.org > >> >> To unsubscribe send an email to python-ideas-le...@python.org > >> >> https://mail.python.org/mailman3/lists/python-ideas.python.org/ > >> >> Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/UT5LEWS4XX5IJ64AMMYKJVG2BNYZXYQY/ > >> >> Code of Conduct: http://python.org/psf/codeofconduct/ > >> > > >> > _______________________________________________ > >> > Python-ideas mailing list -- python-ideas@python.org > >> > To unsubscribe send an email to python-ideas-le...@python.org > >> > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > >> > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/4ZTLXBAQPFYQNITNB3RLRCW5D2QXKGBI/ > >> > Code of Conduct: http://python.org/psf/codeofconduct/ > >> > >> > >> > >> -- > >> Thanks, > >> Andrew Svetlov > > > > -- > Thanks, > Andrew Svetlov >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/GYBEKBHXAEJ2DYKOLD2XZYD7CAXLZJAI/ Code of Conduct: http://python.org/psf/codeofconduct/