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

Wit doesn't work with multiprocessing anymore #18

Closed
walchko opened this issue Mar 23, 2016 · 1 comment
Closed

Wit doesn't work with multiprocessing anymore #18

walchko opened this issue Mar 23, 2016 · 1 comment

Comments

@walchko
Copy link

walchko commented Mar 23, 2016

Hello, I use to be able to use wit with multiprocessing but recently when I started using wit again, this fails now. I made a simple example that shows the failure. I created 2 classes, one with multiprocessing and one without. The multiprocessing class hangs up on wit.query_text() for some reason. If you comment it out and replace it with something like print 'hello!' it works fine. What happened to wit to break this?

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wit
import multiprocessing as mp
import time

token = 'my token'

# a class with multiprocessing
class MP(mp.Process):
    def __init__(self):
        mp.Process.__init__(self)
        wit.init()

    def run(self):
        while True:
            ans = wit.text_query('hello',token)
            print ans
            time.sleep(2)

# just a normal class
class nonMP(object):
    def __init__(self):
        wit.init()

    def run(self):
        while True:
            ans = wit.text_query('hello',token)
            print ans
            time.sleep(2)

    def start(self):
        self.run()
    def join(self):
        a=1

# w = nonMP() # no multiprocessing
w = MP() # with multiprocessing
w.start()
w.join()

Platform: OSX 10.11.1
Python: 2.7.11

@blandinw
Copy link
Contributor

blandinw commented Apr 1, 2016

Thanks @walchko!
We moved to a pure Python version of the library, which should have fixed this issue. The code below works for me (pywit 2.0). Feel free to reopen.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wit
import multiprocessing as mp
import time

token = 'token'

# a class with multiprocessing
class MP(mp.Process):
    def __init__(self):
        mp.Process.__init__(self)

    def run(self):
        while True:
            ans = wit.message(token, 'drive to twitter')
            print ans
            time.sleep(2)

# just a normal class
class nonMP(object):
    def __init__(self):
        pass

    def run(self):
        while True:
            ans = wit.text_query('hello',token)
            print ans
            time.sleep(2)

    def start(self):
        self.run()
    def join(self):
        a=1

# w = nonMP() # no multiprocessing
w = MP() # with multiprocessing
w.start()
w2 = MP()
w2.start()
w.join()
w2.join()

@blandinw blandinw closed this as completed Apr 1, 2016
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

2 participants