Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiprocessing does not work on Goose().extract(raw_html=...) #40

Open
codelucas opened this issue Aug 30, 2013 · 0 comments
Open

Multiprocessing does not work on Goose().extract(raw_html=...) #40

codelucas opened this issue Aug 30, 2013 · 0 comments

Comments

@codelucas
Copy link

This was tested with python's multiprocessing library.

I checked the code, everything hangs at the line prior to Goose().extract(...)
not at join() or run(), etc.

This example is specific but the problem is general. Has anyone gotten multiprocessing to work with
goose's extraction period? If so a brief explanation of how or a tiny code snippet sample would be great thanks.

Or at least an explanation of why my code blow is incorrect would be great.!

Sorry if i'm doing something blatantly wrong. This is my first time
doing multiprocessing in python.

from multiprocessing import Process, Queue
from multiprocessing import cpu_count as num_cores
import pickle
import codecs
from goose import Goose

class Processor(Process):

    def __init__(self, queue, html):
        super(Processor, self).__init__()
        self.queue = queue
        self.html = html

    def ret(self):
        g = Goose()
        article = g.extract(raw_html=self.html)  # THE CODE HANGS HERE
        pickle.dump(article, codecs.open(str(id(article))+'.txt', 'wb'))
        return str(id(article))

    def run(self):
        self.queue.put(self.ret())

processes = []

if __name__ == '__main__':
     for i in range(0, num_cores()):
         q = Queue()
         html = ... 
         p = Processor(q, html)
         processes.append((p, q))
         print 'appending', (p, q)
         p.start()

     for val in processes:
         val[0].join()
         id_ = val[1].get()
         article = pickle.load( codecs.open(id_+'.txt', 'rb'))
         print article.cleaned_text
@codelucas codelucas reopened this Sep 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant