Why Process.fork needs a good alternative in crystal - #14 by ysbaddaden shows a reasonable workaround for executing thread-unsafe code at the start of the process, before the runtime is fully initialized.
Mutating $environ could be implemented in a similar way. But we may need a better hook for that. Currently, even a primitive default execution context is not yet initialized in Crystal.main_user_code, so we cannot use the event loop.
Donāt use that workaround. Donāt promote it.
It should only be used once in a billion-th very specific cases with a clear advantage that has no workaround. It only allows C level programming and is 100% unsafe.
The pdfork case is such a specific case and has clear advantagesāenables security featuresāwith no workaround. But mutating ENV? There are too many workarounds to count. Not worth the hassle.
@zw963 Thereās a SAFETY section on ENV and a WARNING for every method that mutates ENV since Crystal 1.20. See ENV - Crystal 1.20.2