{"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/2448","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/2448/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/2448/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/2448/events","html_url":"https://github.com/tensorflow/tensorflow/issues/2448","id":156076935,"number":2448,"title":"Session got stuck after fork","user":{"login":"ppwwyyxx","id":1381301,"avatar_url":"https://avatars.githubusercontent.com/u/1381301?v=3","gravatar_id":"","url":"https://api.github.com/users/ppwwyyxx","html_url":"https://github.com/ppwwyyxx","followers_url":"https://api.github.com/users/ppwwyyxx/followers","following_url":"https://api.github.com/users/ppwwyyxx/following{/other_user}","gists_url":"https://api.github.com/users/ppwwyyxx/gists{/gist_id}","starred_url":"https://api.github.com/users/ppwwyyxx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ppwwyyxx/subscriptions","organizations_url":"https://api.github.com/users/ppwwyyxx/orgs","repos_url":"https://api.github.com/users/ppwwyyxx/repos","events_url":"https://api.github.com/users/ppwwyyxx/events{/privacy}","received_events_url":"https://api.github.com/users/ppwwyyxx/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-05-21T01:32:13Z","updated_at":"2016-10-20T11:05:58Z","closed_at":"2016-05-21T01:39:59Z","body":"Version: nightly prebuilt for Python2 w/ GPU (just now)\r\n\r\nI'm expecting the following code to print \"10.0\" 3 times, but session.run got stuck in all forked processes.\r\n```python\r\nimport tensorflow as tf\r\nimport multiprocessing as mp\r\nimport os\r\n\r\nclass Worker(mp.Process):\r\n    def __init__(self, gid):\r\n        self.gid = gid\r\n        super(Worker, self).__init__()\r\n\r\n    def run(self):\r\n        G = tf.Graph()\r\n        with G.as_default():\r\n            x = tf.placeholder(tf.float32, shape=[])\r\n            y = x * 2\r\n            sess = tf.Session()\r\n            print sess.run(y, feed_dict={x: 5})\r\n\r\nG = tf.Graph()\r\nwith G.as_default():\r\n    sess = tf.Session()\r\n    with sess.as_default():\r\n        x = tf.placeholder(tf.float32, shape=[])\r\n        y = x * 2\r\n        print sess.run(y, feed_dict={x: 5})\r\n\r\nprocs = [Worker(k) for k in range(2)]\r\nfor p in procs: p.start()\r\nfor p in procs: p.join()\r\n```\r\nRemoving the graph/session in master process will solve the problem. So it seems like once there is a session, we cannot use fork?\r\nThe problem exists with and without GPU.\r\n\r\nNOTE:  this code doesn't terminate normally. You'll probably need to manually kill the forked processes after the master exited. "},"comment":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/comments/255076208","html_url":"https://github.com/tensorflow/tensorflow/issues/2448#issuecomment-255076208","issue_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/2448","id":255076208,"user":{"login":"Liam0205","id":3348485,"avatar_url":"https://avatars.githubusercontent.com/u/3348485?v=3","gravatar_id":"","url":"https://api.github.com/users/Liam0205","html_url":"https://github.com/Liam0205","followers_url":"https://api.github.com/users/Liam0205/followers","following_url":"https://api.github.com/users/Liam0205/following{/other_user}","gists_url":"https://api.github.com/users/Liam0205/gists{/gist_id}","starred_url":"https://api.github.com/users/Liam0205/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Liam0205/subscriptions","organizations_url":"https://api.github.com/users/Liam0205/orgs","repos_url":"https://api.github.com/users/Liam0205/repos","events_url":"https://api.github.com/users/Liam0205/events{/privacy}","received_events_url":"https://api.github.com/users/Liam0205/received_events","type":"User","site_admin":false},"created_at":"2016-10-20T11:05:58Z","updated_at":"2016-10-20T11:05:58Z","body":"@mavenlin \r\nThe prototype of `tf.Session` is\r\n\r\n```python\r\ntf.Session.__init__(target='', graph=None, config=None)\r\n```\r\n\r\nHere `target` refers to the execution engine to connect to. That is, one has to run the working session in another process, in distributed mode, and `tf.Session` with arguments is still not `fork()`-safe.\r\n\r\nSad news."}}
{"actor":{"display_login":"Liam0205"}}