Skip to content

Commit 18dbfeb

Browse files
committed
add subprocess test
1 parent 11709cb commit 18dbfeb

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/cloudpickle_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,5 +403,26 @@ def example():
403403
f = cloudpickle.loads(s)
404404
f() # test
405405

406+
def test_multiprocess(self):
407+
# running a function pickled by another process
408+
def scope():
409+
import curses.textpad
410+
def example():
411+
x = xml.etree.ElementTree.Comment
412+
x = curses.textpad.Textbox
413+
return example
414+
global xml
415+
import xml.etree.ElementTree
416+
example = scope()
417+
418+
s = cloudpickle.dumps(example)
419+
420+
import subprocess
421+
# no point trying "import multiprocessing" because that library
422+
# uses fork to preserve the loaded environment.
423+
assert not subprocess.call(['python', '-c',
424+
'import pickle; (pickle.loads(' +
425+
s.__str__() + '))()'])
426+
406427
if __name__ == '__main__':
407428
unittest.main()

0 commit comments

Comments
 (0)