session
Attributes¶
ctx = mp.get_context('spawn')
module-attribute
¶
_INTERNAL_ATTRS = {'_module', '_module_path', '_environment_conf', '_mgr', '_proc', '_conn', '_shm_pool', '_reg', '_closed', '_func_cache', '_call_remote', '_encode_arg', '_decode_result', '_active_ctx', 'add_contextmanager', 'restart', 'shutdown', 'environment_exists', 'environment_activate', '_run_test_by_name'}
module-attribute
¶
Classes¶
RSessionError
¶
Bases: RuntimeError
Error raised when a worker call fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message (often derived from R error messages). |
required |
remote_traceback
|
str or None
|
Best-effort traceback text from the worker process. For R errors this may be an R traceback string; for Python errors inside the worker it may be a Python traceback. |
None
|
Notes
This exception type is designed to preserve the remote failure context while keeping the main process free of rpy2/R state.
Source code in brmspy/types/errors.py
RWorkerCrashedError
¶
Bases: RuntimeError
Raised when the R worker process crashes during an operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable description of the failure. |
required |
recovered
|
bool
|
Indicates whether a fresh worker session was successfully started.
|
required |
cause
|
BaseException
|
The original exception that triggered the crash. Stored as |
None
|
Usage
In user code or automated pipelines, you can distinguish between a recoverable and unrecoverable crash:
Notes
All crashes automatically produce a new exception that wraps the original
failure using Python's exception chaining (raise ... from cause).
Inspect err.__cause__ for the underlying system error.
Source code in brmspy/types/errors.py
EncodeResult
dataclass
¶
Result of encoding a Python value for IPC transfer.
Attributes:
| Name | Type | Description |
|---|---|---|
codec |
str
|
Codec identifier. |
meta |
dict[str, Any]
|
JSON-serializable metadata required for decoding. |
buffers |
list[ShmRef]
|
Shared-memory blocks backing the encoded payload. |
Source code in brmspy/types/session.py
EnvironmentConfig
dataclass
¶
Worker environment configuration.
This configuration is applied in the worker before importing/using brms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_home
|
str or None
|
Override for |
None
|
startup_scripts
|
list[str]
|
R code snippets executed in the worker after initialization. |
list()
|
environment_name
|
str
|
brmspy environment name (used to determine |
'default'
|
runtime_path
|
str or None
|
Path to a brmspy runtime bundle to activate in the worker. |
None
|
env
|
dict[str, str]
|
Extra environment variables applied when spawning the worker. |
dict()
|
Source code in brmspy/types/session.py
Attributes¶
r_home = None
class-attribute
instance-attribute
¶
startup_scripts = field(default_factory=list)
class-attribute
instance-attribute
¶
environment_name = 'default'
class-attribute
instance-attribute
¶
runtime_path = None
class-attribute
instance-attribute
¶
env = field(default_factory=dict)
class-attribute
instance-attribute
¶
Functions¶
to_dict()
¶
Serialize configuration for persistence to JSON.
Source code in brmspy/types/session.py
from_dict(obj)
classmethod
¶
Deserialize configuration from a JSON object.
Source code in brmspy/types/session.py
from_obj(obj)
classmethod
¶
Normalize None | dict | EnvironmentConfig into an EnvironmentConfig.
Source code in brmspy/types/session.py
__init__(r_home=None, startup_scripts=list(), environment_name='default', runtime_path=None, env=dict())
¶
PayloadRef
¶
Bases: TypedDict
Encoded argument/result payload sent over the control pipe.
A payload is:
codec: the codec identifier used by the registrymeta: JSON-serializable metadata needed to reconstruct the valuebuffers: shared-memory buffer references backing the payload
Source code in brmspy/types/session.py
Request
¶
Bases: TypedDict
IPC request message sent from main process to worker.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Correlation id for the request/response pair. |
cmd |
{'CALL', 'SHUTDOWN', 'PING', '_RUN_TEST_BY_NAME'}
|
Command type. |
target |
str
|
Worker target spec (see |
args, kwargs |
Encoded arguments. |
Source code in brmspy/types/session.py
Response
¶
Bases: TypedDict
IPC response message sent from worker back to the main process.
Source code in brmspy/types/session.py
ShmPool
¶
Bases: ShmPool
Concrete shared-memory pool implementation that temporarily tracks attached blocks.
_blocks dict keeps references to shm buffers TEMPORARILY and is cleaned up before each 'responding to main' or 'sending new message to worker'. This allows the in-between processing of shm buffers to rely on the buffers not being garbage collected.
After reconstructing an object from a shm buffer, it's the CodecRegistrys role to take over the reference by initiating a weakref between the reconstructed object and buffer (or skipping if the object is temporary).
This helps ensure that a minimal amount of shm buffers are actively mapped and garbage collection can remove file descriptors no longer needed.
Source code in brmspy/_session/transport.py
Attributes¶
_manager = manager
instance-attribute
¶
_blocks = {}
instance-attribute
¶
Functions¶
__init__(manager)
¶
alloc(size, temporary=False)
¶
Source code in brmspy/_session/transport.py
attach(ref)
¶
Source code in brmspy/_session/transport.py
close_all()
¶
gc(name=None)
¶
Source code in brmspy/_session/transport.py
ClassProxy
¶
Class-like proxy that exposes only @staticmethod members of a surface class and executes them in the worker.
Worker target format: mod:{module_path}::{class_name}.{method_name}
Source code in brmspy/_session/session.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
Attributes¶
_INTERNAL = {'_session', '_surface_class', '_module_path', '_class_name', '_allowed', '_func_cache'}
class-attribute
instance-attribute
¶
_session = session
instance-attribute
¶
_surface_class = surface_class
instance-attribute
¶
_module_path = module_path
instance-attribute
¶
_class_name = class_name
instance-attribute
¶
_allowed = tuple(sorted(set(allowed)))
instance-attribute
¶
_func_cache = {}
instance-attribute
¶
__all__
property
¶
Functions¶
__init__(*, session, surface_class, module_path, class_name)
¶
Source code in brmspy/_session/session.py
__getattribute__(name)
¶
Source code in brmspy/_session/session.py
__dir__()
¶
RModuleSession
¶
Bases: ModuleType
Module-like proxy that forwards attribute access and function calls to a worker process.
In the main process, brmspy.brms is an instance of this class wrapping the
real worker-side module. Access patterns are:
- Callables (functions) are wrapped so calling them performs an IPC roundtrip: encode args/kwargs → send request → run in worker → encode result → decode result.
- Non-callables (constants, types) are mirrored directly from the wrapped module
to keep
dir()and IDE autocomplete useful.
This class also owns the worker lifecycle:
- creates a
SharedMemoryManagerfor large payload buffers - spawns the worker process using spawn semantics
- bridges worker logging back into the parent's handlers via a log queue
- performs a
PINGhandshake to ensure the worker is ready before requests
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
ModuleType
|
The module object whose surface is mirrored in the main process. In practice
this is the import of the worker-facing module (e.g. |
required |
module_path
|
str
|
Import path used inside the worker when resolving targets (e.g. |
required |
environment_conf
|
EnvironmentConfig | dict[str, Any] | None
|
Initial environment configuration for the worker. If omitted, brmspy will try
to load |
None
|
Notes
- The main process must not import
rpy2.robjects; the worker owns all embedded-R state. - Any R objects returned by the worker are replaced with lightweight wrappers and can only be reattached inside the same worker process lifetime.
Source code in brmspy/_session/session.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 | |
Attributes¶
_instances = weakref.WeakSet()
class-attribute
instance-attribute
¶
_atexit_registered = False
class-attribute
instance-attribute
¶
_is_rsession = True
class-attribute
instance-attribute
¶
_module = module
instance-attribute
¶
_module_path = module_path
instance-attribute
¶
_environment_conf = EnvironmentConfig.from_obj(environment_conf)
instance-attribute
¶
_func_cache = {}
instance-attribute
¶
_active_ctx = None
instance-attribute
¶
_closed = True
instance-attribute
¶
Functions¶
__init__(module, module_path, environment_conf=None)
¶
Create a new session proxy and immediately start its worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
ModuleType
|
Wrapped module used for surface mirroring in the main process. |
required |
module_path
|
str
|
Worker import root used for resolving targets. |
required |
environment_conf
|
EnvironmentConfig | dict[str, Any] | None
|
Initial worker environment configuration. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the worker fails to start or does not respond to the startup handshake. |
Source code in brmspy/_session/session.py
_setup_worker(autoload=True)
¶
Start the SHM manager + worker process and perform the startup handshake.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
autoload
|
bool
|
If True, sets |
True
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the worker fails to start within the handshake timeout or reports an init error. |
Source code in brmspy/_session/session.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
_teardown_worker()
¶
Tear down worker process, SHM manager, and logging bridge.
This is best-effort cleanup used by shutdown() and restart():
- sends
SHUTDOWN(non-fatal if it fails) - stops the
QueueListenerfor worker logging - shuts down the
SharedMemoryManager - joins/terminates the worker if needed
Notes
The "join then terminate" sequence is intentional to avoid leaving zombie processes behind in interactive environments.
Source code in brmspy/_session/session.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
_cleanup_all()
classmethod
¶
Atexit hook to shut down all live sessions.
This is registered once for the class and iterates over a WeakSet of
RModuleSession instances.
Source code in brmspy/_session/session.py
_encode_arg(obj)
¶
Encode a single Python argument into an IPC payload dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Value to encode. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A JSON-serializable structure containing:
|
Source code in brmspy/_session/session.py
_decode_result(resp)
¶
Decode a worker response into a Python value or raise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resp
|
dict[str, Any]
|
Response message from the worker. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Decoded Python object. |
Raises:
| Type | Description |
|---|---|
RSessionError
|
If |
Source code in brmspy/_session/session.py
_call_remote(func_name, *args, **kwargs)
¶
Perform a remote call in the worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func_name
|
str
|
Function name or fully qualified target.
|
required |
*args
|
Any
|
Call arguments, encoded via the session codec registry. |
()
|
**kwargs
|
Any
|
Call arguments, encoded via the session codec registry. |
()
|
Returns:
| Type | Description |
|---|---|
Any
|
Decoded return value. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the session has been shut down. |
RSessionError
|
If the worker reports an error while executing the call. |
Source code in brmspy/_session/session.py
_recover(orig_exc)
¶
Source code in brmspy/_session/session.py
__getattribute__(name)
¶
Proxy attribute access for a module-like experience.
Rules
- Internal attributes are handled locally.
- Callables found on the wrapped module are returned as wrappers that call into the worker.
- Non-callables are mirrored directly.
Source code in brmspy/_session/session.py
_get_or_create_wrapper(name, orig)
¶
Return a cached worker-calling wrapper for a callable attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Attribute name on the wrapped module. |
required |
orig
|
Callable[..., Any]
|
Original callable (used for metadata only). |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., Any]
|
Wrapper that performs an IPC roundtrip to execute the callable in the worker. |
Source code in brmspy/_session/session.py
__dir__()
¶
Expose the merged surface of the proxy and the wrapped module.
shutdown()
¶
__del__()
¶
add_contextmanager(*, surface_class, surface_class_path)
¶
Attach a class-based "surface" API as a context manager factory.
This is used to implement brmspy.brms.manage() and brmspy.brms._build()
without exposing worker internals to the main process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
surface_class
|
type
|
Class whose |
required |
surface_class_path
|
str
|
Fully qualified path like |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., AbstractContextManager]
|
Factory that produces a context manager. On enter it restarts the worker
(autoload disabled) and yields a |
Notes
- Nesting contexts is forbidden; this is enforced via
self._active_ctx. - On exit, the selected environment config is persisted via the environment store.
Source code in brmspy/_session/session.py
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | |
restart(environment_conf=None, autoload=True)
¶
Restart the worker process and SHM manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
environment_conf
|
dict[str, Any] | EnvironmentConfig | None
|
If provided, replaces the existing environment configuration for the new worker. |
None
|
autoload
|
bool
|
Whether to enable autoload for the new worker process. |
True
|
Notes
This tears down the existing worker and starts a new one. Any previously returned R object wrappers are no longer reattachable after restart.
Source code in brmspy/_session/session.py
environment_exists(name)
¶
Check whether an environment with the given name exists on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Environment name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in brmspy/_session/session.py
environment_activate(name)
¶
Activate an environment by restarting the worker through manage().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Environment name to activate. |
required |
Notes
This is a convenience helper used by tests and developer flows.
Source code in brmspy/_session/session.py
_run_test_by_name(module_path, class_name, func_name)
¶
Run a test identified by module/class/function inside the worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
str
|
Importable module path (e.g. |
required |
class_name
|
str | None
|
Optional class name if the test is a method. |
required |
func_name
|
str
|
Test function/method name. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Decoded return value from the test function. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
RSessionError
|
If the worker reports a failure. |
Source code in brmspy/_session/session.py
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 | |
Functions¶
get_environment_config(name)
¶
Load an environment configuration from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Environment name. |
required |
Returns:
| Type | Description |
|---|---|
EnvironmentConfig
|
Loaded configuration. If no config file exists, returns a default config
with |
Source code in brmspy/_session/environment.py
get_environment_exists(name)
¶
Return True if an environment exists (determined by presence of config.json).
Source code in brmspy/_session/environment.py
save(env_conf)
¶
Persist an environment configuration and ensure the directory structure exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_conf
|
EnvironmentConfig
|
Environment configuration to write. |
required |
Source code in brmspy/_session/environment_parent.py
save_as_state(env_conf)
¶
Record the active environment name in environment_state.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_conf
|
EnvironmentConfig
|
Environment configuration whose name should be recorded. |
required |
Source code in brmspy/_session/environment_parent.py
get_logger()
¶
Get or create the brmspy logger instance.
Returns a configured logger with a custom formatter that outputs
messages in the format: [brmspy][method_name] msg here
Returns:
| Type | Description |
|---|---|
Logger
|
Configured brmspy logger instance |
Examples:
>>> from brmspy.helpers.log import get_logger
>>> logger = get_logger()
>>> logger.info("Starting process") # Prints: [brmspy][<module>] Starting process
Source code in brmspy/helpers/log.py
log_warning(msg, method_name=None)
¶
Log a warning message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
The warning message to log |
required |
method_name
|
str
|
The name of the method/function. If None, will auto-detect from call stack. |
None
|
Source code in brmspy/helpers/log.py
get_default_registry()
¶
Return the process-global default codec registry.
Returns:
| Type | Description |
|---|---|
CodecRegistry
|
Registry with SHM-first codecs registered, plus a pickle fallback. |
Source code in brmspy/_session/codec/registry.py
worker_main(conn, mgr_address, mgr_authkey, runtime_conf, log_queue)
¶
Worker entrypoint.
- Connects to the already-running SharedMemoryManager (started in parent)
- Optionally configures R env via
runtime_conf - Receives CALL/SHUTDOWN commands over
conn - Executes Python functions in modules inside this worker. Those modules are free to use rpy2 / brms / cmdstanr however they like.
Source code in brmspy/_session/worker/worker.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
r_home_from_subprocess()
¶
Return the R home directory by calling R RHOME in a subprocess.
Source code in brmspy/_session/session.py
add_env_defaults(overrides)
¶
Ensure required R environment variables exist inside overrides. Mutates overrides in-place and returns it.
- Ensures R_HOME exists (or auto-detects)
- Ensures LD_LIBRARY_PATH includes R_HOME/lib (Unix only)
Source code in brmspy/_session/session.py
with_env(overrides)
¶
Temporarily apply environment overrides, then restore.
Source code in brmspy/_session/session.py
spawn_worker(target, args, env_overrides, log_queue=None)
¶
Spawn the worker process with temporary environment overrides.
Notes
- brmspy uses spawn semantics (see
ctx = mp.get_context("spawn")). - The worker receives the log queue as an extra trailing argument when present.