Skip to content

Commit

Permalink
add subprocess test
Browse files Browse the repository at this point in the history
  • Loading branch information
benjimin committed Feb 12, 2017
1 parent 11709cb commit 6854eaa
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 6854eaa

Please sign in to comment.