<div><br><div class="gmail_quote"><div dir="auto">On Sun, Jun 25, 2017 at 4:54 PM Chris Jerdonek <<a href="mailto:chris.jerdonek@gmail.com">chris.jerdonek@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The read-write operations I'm protecting will have coroutines inside<br>
that need to be awaited on, so I don't think I'll be able to take<br>
advantage to that extreme.<br>
<br>
But I think I might be able to use your point to simplify the logic a<br>
little. (To rephrase, you're reminding me that context switches can't<br>
happen at arbitrary lines of code. I only need to be prepared for the<br>
cases where there's an await / yield from.)</blockquote><div dir="auto"><br></div><div dir="auto">The "secret" Guido refers to we should pull out front and center, explicitly at all times - asynchronous programming is nothing more than cooperative multitasking.</div><div dir="auto"><br></div><div dir="auto">Patterns suited for preemptive multi-tasking (executive-based, interrupt based, etc.) are suspect, potentially misplaced when they show up in a cooperative multitasking context.</div><div dir="auto"><br></div><div dir="auto">To be a well-behaved (capable of effective cooperation) task in such a system, you should guard against getting embroiled in potentially blocking I/O tasks whose latency you are not able to control (within facilities available in a cooperative multitasking context).  The raises a couple of questions: to be well-behaved, simple control flow is desireable (i.e. not nested layers of yields, except perhaps for a pipeline case); and "read/write" control from memory space w/in the process (since external I/O is generally not for async) begs the question: what for?  Eliminate globals, encapsulate and limit access as needed theough usual programming methods.</div><div dir="auto"><br></div><div dir="auto">I'm sure someone will find an edgecase to challenge my above rule-of-thumb, but as you're new to this, I think this is a pretty good place to start.  Ask yourself if what your trying to do w/ async is suited for async.</div><div dir="auto"><br></div><div dir="auto">Cheers,</div><div dir="auto">Yarko</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
--Chris<br>
<br>
<br>
On Sun, Jun 25, 2017 at 2:30 PM, Guido van Rossum <<a href="mailto:gvanrossum@gmail.com" target="_blank">gvanrossum@gmail.com</a>> wrote:<br>
> The secret is that as long as you don't yield no other task will run so you<br>
> don't need locks at all.<br>
><br>
> On Jun 25, 2017 2:24 PM, "Chris Jerdonek" <<a href="mailto:chris.jerdonek@gmail.com" target="_blank">chris.jerdonek@gmail.com</a>> wrote:<br>
>><br>
>> Thank you. I had seen that, but it seems heavier weight than needed.<br>
>> And it also requires locking on reading.<br>
>><br>
>> --Chris<br>
>><br>
>> On Sun, Jun 25, 2017 at 2:16 PM, Andrew Svetlov<br>
>> <<a href="mailto:andrew.svetlov@gmail.com" target="_blank">andrew.svetlov@gmail.com</a>> wrote:<br>
>> > There is <a href="https://github.com/aio-libs/aiorwlock" rel="noreferrer" target="_blank">https://github.com/aio-libs/aiorwlock</a><br>
>> ><br>
>> > On Mon, Jun 26, 2017 at 12:13 AM Chris Jerdonek<br>
>> > <<a href="mailto:chris.jerdonek@gmail.com" target="_blank">chris.jerdonek@gmail.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> I'm relatively new to async programming in Python and am thinking<br>
>> >> through possibilities for doing "read-write" synchronization.<br>
>> >><br>
>> >> I'm using asyncio, and the synchronization primitives that asyncio<br>
>> >> exposes are relatively simple [1]. Have options for async read-write<br>
>> >> synchronization already been discussed in any detail?<br>
>> >><br>
>> >> I'm interested in designs where "readers" don't need to acquire a lock<br>
>> >> -- only writers. It seems like one way to deal with the main race<br>
>> >> condition I see that comes up would be to use loop.time(). Does that<br>
>> >> ring a bell, or might there be a much simpler way?<br>
>> >><br>
>> >> Thanks,<br>
>> >> --Chris<br>
>> >><br>
>> >><br>
>> >> [1] <a href="https://docs.python.org/3/library/asyncio-sync.html" rel="noreferrer" target="_blank">https://docs.python.org/3/library/asyncio-sync.html</a><br>
>> >> _______________________________________________<br>
>> >> Async-sig mailing list<br>
>> >> <a href="mailto:Async-sig@python.org" target="_blank">Async-sig@python.org</a><br>
>> >> <a href="https://mail.python.org/mailman/listinfo/async-sig" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/async-sig</a><br>
>> >> Code of Conduct: <a href="https://www.python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">https://www.python.org/psf/codeofconduct/</a><br>
>> ><br>
>> > --<br>
>> > Thanks,<br>
>> > Andrew Svetlov<br>
>> _______________________________________________<br>
>> Async-sig mailing list<br>
>> <a href="mailto:Async-sig@python.org" target="_blank">Async-sig@python.org</a><br>
>> <a href="https://mail.python.org/mailman/listinfo/async-sig" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/async-sig</a><br>
>> Code of Conduct: <a href="https://www.python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">https://www.python.org/psf/codeofconduct/</a><br>
_______________________________________________<br>
Async-sig mailing list<br>
<a href="mailto:Async-sig@python.org" target="_blank">Async-sig@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/async-sig" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/async-sig</a><br>
Code of Conduct: <a href="https://www.python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">https://www.python.org/psf/codeofconduct/</a><br>
</blockquote></div></div>