Andrew Svetlov <andrew.svet...@gmail.com> added the comment:

My initial thought was protecting the Lock (and other primitives) creation when 
a loop is not running.

Yuri insists that Lock can be created without a loop. Technically it is 
possible, sure.
But the lock is tightly coupled with a loop instance. In other words, the loop 
belongs to the loop.
The lock cannot be used after the loop dies (stopped and closed).

Thus, the global scoped lock object still looks suspicious in my eyes.
The lock's lifecycle should be closer than the lifecycle of the loop, isn't it? 
I know, asyncio.Lock() can safely live after the loop closing but should we 
encourage this style? There are many other asyncio objects like HTTP clients 
and DB drivers that should be closed before the loop finishing for graceful 
closing TCP transports etc.

Another thing to consider is: whether to cache a loop inside a lock;  whether 
to add a check when the lock is used by two loops?

I think for the last question the answer is "yes". I recall many questions and 
bug reports on StackOverflow and aiohttp bug tracker when people use the 
multithreaded model for some reason and tries to get access to a shared object 
from different threads that executes each own loop.

The check becomes extremely important for synchronization primitives like 
asyncio.Lock class; threading.Lock is supposed to be shared between threads and 
users can apply the same pattern for asyncio.Lock by oversight.
Also, supporting global asyncio.Lock instances increase the chance that the 
lock is used by different loops.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42392>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to