This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author asvetlov
Recipients aeros, asvetlov, yselivanov
Date 2020-11-18.12:15:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605701719.34.0.0130210324378.issue42392@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-11-18 12:15:19asvetlovsetrecipients: + asvetlov, yselivanov, aeros
2020-11-18 12:15:19asvetlovsetmessageid: <1605701719.34.0.0130210324378.issue42392@roundup.psfhosted.org>
2020-11-18 12:15:19asvetlovlinkissue42392 messages
2020-11-18 12:15:18asvetlovcreate