GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-109370: Support closing Connection and PipeConnection from other thread by serhiy-storchaka · Pull Request #109397 · python/cpython Conversation
|
|
I do not like this.
I have not tested the code on Windows yet, very likely more try/exept or return code checks should be added in Windows specific code. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| _winapi.PeekNamedPipe(self._handle)[0] != 0): | ||
| return True | ||
| except OSError as err: | ||
| if err.errno == errno.EBADF: |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We should not get EBADF. We should just not call functions on closed handle. If we land in this case, we failed badly before, no?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
How can we know that it was closed in other thread without using locks?
You can get EBADF in the following scenario:
self._handle and puts in on the stack.It is the bast case. The worst case is:
self._handle and puts in on the stack.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| raise | ||
| except TypeError: | ||
| self._check_closed() | ||
| raise |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to split this change in two parts? Keep this change for _check_closed() change which now raises BrokenPipeError, and you changes around close(): these ones look straightforward are correct. But write a separated PR to add these try/except?
I dislike these try/except. If there is a risk to land into EBADF case with the current code, maybe some kind of locking is needed to not call the Windows API with a handle, while another thread call close() which invalidates the handle.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The more I look at this, the more I dislike it. I do not see how is it possible to safely close a file descriptor on other thread without locking. Making Connection and PipeConnection truly thread-safe in a task on completely different level. I opened #109780 instead. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Maybe we should just give up and document that they are not thread-safe. I recall that I did that once on some asyncio classes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.