From 41429996fc3b0e4313e0d81196932a21db6b4a5d Mon Sep 17 00:00:00 2001 From: Wang Jiajun Date: Wed, 20 Mar 2019 12:21:00 +0800 Subject: [PATCH] add docs --- docs/tutorials/gluon/customop.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/tutorials/gluon/customop.md b/docs/tutorials/gluon/customop.md index eae0344c8702..346514223314 100644 --- a/docs/tutorials/gluon/customop.md +++ b/docs/tutorials/gluon/customop.md @@ -30,6 +30,7 @@ Custom operator in python is easy to develop and good for prototyping, but may h import numpy as np import mxnet as mx from mxnet import gluon, autograd +import os ``` ## Parameter-less operators @@ -214,5 +215,20 @@ y = dense(x) print(y) ``` +## Using custom operators with fork +In Linux systems, the default method in multiprocessing to create process is by using fork. If there are unfinished async custom operations when forking, the program will be blocked because of python GIL. + +``` +x = mx.nd.array([0, 1, 2, 3]) +y = mx.nd.Custom(x, op_type='sigmoid') +os.fork() +``` + +Correctly handling this will make mxnet depend upon libpython, so the workaround now is to ensure all custom operation is executed before forking process. + +``` +print(y.asnumpy()) +os.fork() +```