Add util functions for pickling and unpickling multiprocessing.Connection
This commit is contained in:
parent
d9a71ca6f9
commit
65fcfbfae9
@ -1,4 +1,6 @@
|
||||
import logging
|
||||
from multiprocessing.reduction import reduce_connection
|
||||
import pickle
|
||||
|
||||
from mopidy import settings as raw_settings
|
||||
|
||||
@ -18,6 +20,16 @@ def get_class(name):
|
||||
class_object = getattr(module, class_name)
|
||||
return class_object
|
||||
|
||||
def pickle_connection(connection):
|
||||
return pickle.dumps(reduce_connection(connection))
|
||||
|
||||
def unpickle_connection(pickled_connection):
|
||||
# From http://stackoverflow.com/questions/1446004
|
||||
unpickled = pickle.loads(pickled_connection)
|
||||
func = unpickled[0]
|
||||
args = unpickled[1]
|
||||
return func(*args)
|
||||
|
||||
class SettingsError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user