◐ Shell
reader mode source ↗
Skip to content

gh-109370: Support closing Connection and PipeConnection from other thread#109397

Closed
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:multiprocessing-connection-close
Closed

gh-109370: Support closing Connection and PipeConnection from other thread#109397
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:multiprocessing-connection-close

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 14, 2023

Copy link
Copy Markdown
Member

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

I do not like this.

  1. It is too complicated and verbose.
  2. There is still a chance for race condition, if between pushing self.handler on the stack and calling the corresponding OS function, the handler was closed and a new file was open that reuses the same fileno.

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.

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

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.

@vstinner

vstinner commented Sep 25, 2023

Copy link
Copy Markdown
Member

Making Connection and PipeConnection truly thread-safe in a task on completely different level.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants