diff --git a/tests/cloudpickle_test.py b/tests/cloudpickle_test.py index b71e356a8..025c94ae0 100644 --- a/tests/cloudpickle_test.py +++ b/tests/cloudpickle_test.py @@ -9,6 +9,8 @@ import itertools import platform import textwrap +import base64 +import subprocess try: # try importing numpy and scipy. These are not hard dependencies and @@ -403,5 +405,27 @@ def example(): f = cloudpickle.loads(s) f() # test + def test_multiprocess(self): + # running a function pickled by another process (a la dask.distributed) + def scope(): + import curses.textpad + def example(): + x = xml.etree.ElementTree.Comment + x = curses.textpad.Textbox + return example + global xml + import xml.etree.ElementTree + example = scope() + + s = cloudpickle.dumps(example) + + # choose "subprocess" rather than "multiprocessing" because the latter + # library uses fork to preserve the parent environment. + command = ("import pickle, base64; " + "pickle.loads(base64.b32decode('" + + base64.b32encode(s).decode('ascii') + + "'))()") + assert not subprocess.call([sys.executable, '-c', command]) + if __name__ == '__main__': unittest.main()