ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: mame@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:103426] [Ruby master Feature#5446] at_fork callback API
Date: Tue, 13 Apr 2021 14:30:58 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-91519.20210413143057.724@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-5446.20111014111058.724@ruby-lang.org

Issue #5446 has been updated by mame (Yusuke Endoh).

Status changed from Assigned to Closed

byroot (Jean Boussier) wrote in #note-52:
> @mame I created https://bugs.ruby-lang.org/issues/17795, let me know if it makes sense to you, in which case I'll update my developer meeting request.

Thank you, it is very clear!

I'm closing this ticket since its goal was drifted over the years. If anyone is not satisfied, let me know.

----------------------------------------
Feature #5446: at_fork callback API
https://bugs.ruby-lang.org/issues/5446#change-91519

* Author: normalperson (Eric Wong)
* Status: Closed
* Priority: Normal
* Assignee: kosaki (Motohiro KOSAKI)
----------------------------------------
It would be good if Ruby provides an API for registering fork() handlers.

This allows libraries to automatically and agnostically reinitialize resources
such as open IO objects in child processes whenever fork() is called by a user
application.  Use of this API by library authors will reduce false/improper
sharing of objects across processes when interacting with other
libraries/applications that may fork.

This Ruby API should function similarly to pthread_atfork() which allows
(at least) three different callbacks to be registered:

1) prepare - called before fork() in the original process
2) parent - called after fork() in the original process
3) child - called after fork() in the child process

It should be possible to register multiple callbacks for each action
(like at_exit and pthread_atfork(3)).

These callbacks should be called whenever fork() is used:

- Kernel#fork
- IO.popen
- ``
- Kernel#system

... And any other APIs I've forgotten about

I also want to consider handlers that only need to be called for plain
fork() use (without immediate exec() afterwards, like with `` and system()).

Ruby already has the internal support for most of this this to manage mutexes,
Thread structures, and RNG seed.  Currently, no external API is exposed.  I can
prepare a patch if an API is decided upon.




-- 
https://bugs.ruby-lang.org/

      parent reply	other threads:[~2021-04-13 14:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-5446.20111014111058.724@ruby-lang.org>
2021-04-03 14:16 ` [ruby-core:103197] [Ruby master Feature#5446] at_fork callback API jean.boussier
2021-04-04  5:34   ` [ruby-core:103199] " Eric Wong
2021-04-03 14:17 ` [ruby-core:103198] " jean.boussier
2021-04-04 10:52 ` [ruby-core:103202] " eregontp
2021-04-04 20:40   ` [ruby-core:103208] " Eric Wong
2021-04-04 21:17     ` [ruby-core:103209] " Eric Wong
2021-04-04 10:55 ` [ruby-core:103203] " eregontp
2021-04-04 18:40 ` [ruby-core:103205] " jean.boussier
2021-04-04 18:44 ` [ruby-core:103206] " jean.boussier
2021-04-04 19:19 ` [ruby-core:103207] " daniel
2021-04-04 21:55 ` [ruby-core:103210] " jean.boussier
2021-04-04 22:26 ` [ruby-core:103212] " jean.boussier
2021-04-05  3:07 ` [ruby-core:103235] " daniel
2021-04-06 10:50 ` [ruby-core:103254] " jean.boussier
2021-04-08  8:31 ` [ruby-core:103297] " ivo.anjo
2021-04-12  5:30 ` [ruby-core:103393] " mame
2021-04-12  6:52 ` [ruby-core:103397] " jean.boussier
2021-04-12  7:52 ` [ruby-core:103399] " mame
2021-04-12  8:09 ` [ruby-core:103401] " jean.boussier
2021-04-13 14:30 ` mame [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-91519.20210413143057.724@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).