{"action":"created","issue":{"url":"https://api.github.com/repos/debugtalk/ApiTestEngine/issues/47","repository_url":"https://api.github.com/repos/debugtalk/ApiTestEngine","labels_url":"https://api.github.com/repos/debugtalk/ApiTestEngine/issues/47/labels{/name}","comments_url":"https://api.github.com/repos/debugtalk/ApiTestEngine/issues/47/comments","events_url":"https://api.github.com/repos/debugtalk/ApiTestEngine/issues/47/events","html_url":"https://github.com/debugtalk/ApiTestEngine/issues/47","id":265160560,"number":47,"title":"【演示脚本test_apiserver.py运行错误】TypeError: can't pickle thread.lock objects ","user":{"login":"firefoxwang","id":16410686,"avatar_url":"https://avatars2.githubusercontent.com/u/16410686?v=4","gravatar_id":"","url":"https://api.github.com/users/firefoxwang","html_url":"https://github.com/firefoxwang","followers_url":"https://api.github.com/users/firefoxwang/followers","following_url":"https://api.github.com/users/firefoxwang/following{/other_user}","gists_url":"https://api.github.com/users/firefoxwang/gists{/gist_id}","starred_url":"https://api.github.com/users/firefoxwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firefoxwang/subscriptions","organizations_url":"https://api.github.com/users/firefoxwang/orgs","repos_url":"https://api.github.com/users/firefoxwang/repos","events_url":"https://api.github.com/users/firefoxwang/events{/privacy}","received_events_url":"https://api.github.com/users/firefoxwang/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-10-13T03:39:25Z","updated_at":"2017-10-13T09:24:38Z","closed_at":"2017-10-13T09:24:38Z","author_association":"NONE","body":"【运行环境】:\r\n    系统：win7 \r\n    编辑器：pycharm2017\r\n    软件环境：python2.7.13\r\n\r\n【运行步骤】\r\n    在pycharm里运行test_apiserver.py脚本 执行单元测试 报进程错误 \r\nTypeError: can't pickle thread.lock objects \r\n\r\n 【错误回溯】\r\nFailure\r\nTraceback (most recent call last):\r\n  File \"D:\\Python27\\Lib\\unittest\\suite.py\", line 146, in _handleClassSetUp\r\n    setUpClass()\r\n  File \"D:\\python_project\\ApiTestEngine\\tests\\base.py\", line 20, in setUpClass\r\n    cls.api_server_process.start()\r\n  File \"D:\\Python27\\Lib\\multiprocessing\\process.py\", line 130, in start\r\n    self._popen = Popen(self)\r\n  File \"D:\\Python27\\Lib\\multiprocessing\\forking.py\", line 277, in __init__\r\n    dump(process_obj, to_child, HIGHEST_PROTOCOL)\r\n  File \"D:\\Python27\\Lib\\multiprocessing\\forking.py\", line 199, in dump\r\n    ForkingPickler(file, protocol).dump(obj)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 224, in dump\r\n    self.save(obj)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 331, in save\r\n    self.save_reduce(obj=obj, *rv)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 425, in save_reduce\r\n    save(state)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 286, in save\r\n    f(self, obj) # Call unbound method with explicit self\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 655, in save_dict\r\n    self._batch_setitems(obj.iteritems())\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 687, in _batch_setitems\r\n    save(v)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 286, in save\r\n    f(self, obj) # Call unbound method with explicit self\r\n  File \"D:\\Python27\\Lib\\multiprocessing\\forking.py\", line 67, in dispatcher\r\n    self.save_reduce(obj=obj, *rv)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 401, in save_reduce\r\n    save(args)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 286, in save\r\n    f(self, obj) # Call unbound method with explicit self\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 554, in save_tuple\r\n    save(element)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 331, in save\r\n    self.save_reduce(obj=obj, *rv)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 425, in save_reduce\r\n    save(state)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 286, in save\r\n    f(self, obj) # Call unbound method with explicit self\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 655, in save_dict\r\n    self._batch_setitems(obj.iteritems())\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 687, in _batch_setitems\r\n    save(v)\r\n  File \"D:\\Python27\\Lib\\pickle.py\", line 306, in save\r\n    rv = reduce(self.proto)\r\nTypeError: can't pickle thread.lock objects\r\n\r\n     "},"comment":{"url":"https://api.github.com/repos/debugtalk/ApiTestEngine/issues/comments/336399781","html_url":"https://github.com/debugtalk/ApiTestEngine/issues/47#issuecomment-336399781","issue_url":"https://api.github.com/repos/debugtalk/ApiTestEngine/issues/47","id":336399781,"user":{"login":"firefoxwang","id":16410686,"avatar_url":"https://avatars2.githubusercontent.com/u/16410686?v=4","gravatar_id":"","url":"https://api.github.com/users/firefoxwang","html_url":"https://github.com/firefoxwang","followers_url":"https://api.github.com/users/firefoxwang/followers","following_url":"https://api.github.com/users/firefoxwang/following{/other_user}","gists_url":"https://api.github.com/users/firefoxwang/gists{/gist_id}","starred_url":"https://api.github.com/users/firefoxwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firefoxwang/subscriptions","organizations_url":"https://api.github.com/users/firefoxwang/orgs","repos_url":"https://api.github.com/users/firefoxwang/repos","events_url":"https://api.github.com/users/firefoxwang/events{/privacy}","received_events_url":"https://api.github.com/users/firefoxwang/received_events","type":"User","site_admin":false},"created_at":"2017-10-13T09:24:38Z","updated_at":"2017-10-13T09:24:38Z","author_association":"NONE","body":"找到问题的原因了，Process类的入参，target是需要“defined at the top-level of a module”。具体的可以[看这里](https://stackoverflow.com/questions/8804830/python-multiprocessing-pickling-error)，最高票回答的讲解。\r\n『解决方法』: 1.在base.py脚本中添加\r\n`def apprun():\r\n    _ = api_server.app.run()`\r\n2.修改test_apiserver.py的第十八行为 ` target=apprun`"}}
{"actor":{"display_login":"firefoxwang"}}