forked from lenskit/lkpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable generalized sharing capabilities
- Loading branch information
1 parent
7ae38bc
commit 1acbfdd
Showing
4 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Support for sharing and saving models and data structures. | ||
""" | ||
|
||
from contextlib import contextmanager | ||
|
||
__save_mode = 'save' | ||
|
||
|
||
@contextmanager | ||
def sharing_mode(): | ||
""" | ||
Context manager to tell models that pickling will be used for cross-process | ||
sharing, not model persistence. | ||
""" | ||
global __save_mode | ||
old = __save_mode | ||
__save_mode = 'share' | ||
try: | ||
yield | ||
finally: | ||
__save_mode = old | ||
|
||
|
||
def in_share_context(): | ||
""" | ||
Query whether sharing mode is active. If ``True``, we are currently in a | ||
:fun:`sharing_mode` context, which means model pickling will be used for | ||
cross-process sharing. | ||
""" | ||
return __save_mode == 'share' |