Skip to content

Instantly share code, notes, and snippets.

@aniketp
Created June 28, 2018 20:08
Show Gist options
  • Save aniketp/95f2c3544b697d422ac23a064523d6c3 to your computer and use it in GitHub Desktop.
Save aniketp/95f2c3544b697d422ac23a064523d6c3 to your computer and use it in GitHub Desktop.
from multiprocessing import Process, Manager
from fasttext import FastVector
# Returns a sample fastVector object
def createFastVector():
# Create for English vector-wiki
en_dict = FastVector(vector_file='wiki.en.vec')
return en_dict
def serverFunc(vector):
print(vector)
# Result: Namespace(en_vector=<__main__.FastVector object at 0x7fb018fbadd8>)
if __name__ == '__main__':
manager = Manager()
fastVector = createFastVector()
# Using Managers.Namespace to store fastVector object
vector = manager.Namespace()
vector.en_vector = fastVector
# Multiple such processes can be used to send a READ request
# to target function, i.e the server hosting FastVector object
process = Process(target=serverFunc, args=(vector))
process.start()
process.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment