Multiprocessing Share Unserializable Objects Between Processes

后端 未结 3 2105
抹茶落季
抹茶落季 2020-12-03 07:38

There are three questions as possible duplicates (but too specific):

  • How to properly set up multiprocessing proxy objects for objects that already exist
3条回答
  •  臣服心动
    2020-12-03 08:42

    Just use stackless python. You can serialize almost anything with pickle, including functions. Here I serialize and deserialize a lambda using the pickle module. This is similar to what you are trying to do in your example.

    Here is the download link for Stackless Python http://www.stackless.com/wiki/Download

    Python 2.7.5 Stackless 3.1b3 060516 (default, Sep 23 2013, 20:17:03) 
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> f = 5
    >>> g = lambda : f * f
    >>> g()
    25
    >>> import pickle
    >>> p = pickle.dumps(g)
    >>> m = pickle.loads(p)
    >>> m()
    25
    >>> 
    

提交回复
热议问题