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

Improve list representations, unicode support and multiple threading usage #97

Merged
merged 6 commits into from
Jul 7, 2020

Conversation

g-gemignani
Copy link
Contributor

Hello,

we have been using this library at Magazino GmbH for quite a while now and made some improvements on top of it.
We would like to contribute back, hence this PR.
Changes:

  • Improved list representation
  • Solved an issue with pyswip, which was segfaulting when multiple threads were using the lib
  • Add unicode support for python 2

@yuce
Copy link
Owner

yuce commented Jul 7, 2020

@g-gemignani Thanks a lot for your contribution!

Could you add your name to CONTRIBUTORS?

Are there any plans to migrate to Python 3 on your side soon?

I will add a section to the README to list companies that use PySwip. Hopefully that will increase the awareness to PySwip. Would it be a problem if I list Magazino GmbH under that section?

@g-gemignani
Copy link
Contributor Author

Hi @yuce, thank you for the quick reply. I just added my name to the contributors. At Magazino we are slowly transitioning to python 3 and I believe we should complete the transition in the next few months. About adding Magazino to the list of companies using PySwip, I asked the company and there are no issues from our side. Thank you! :)

@yuce
Copy link
Owner

yuce commented Jul 7, 2020

That's great, thanks!

@yuce yuce merged commit b2e1cd4 into yuce:master Jul 7, 2020
@vakker
Copy link
Contributor

vakker commented Sep 11, 2020

@g-gemignani the multi-threading improvement looks great!
Could you provide a brief snippet that utilises that?

@g-gemignani
Copy link
Contributor Author

Hi @vakker,

thanks for the comment. I need to check what I can share but I can tell you the idea behind the snippet and how we use it.
We use this library together with ROS (https://it.wikipedia.org/wiki/Robot_Operating_System). In ROS you can define nodes that provide services to other nodes using TCP communications. We use that snippet of code to support having multiple nodes connecting to the main server and asking for multiple services to be executed. The central node acts as a single interface to the prolog world. That is why we need the multiple threading feature. I guess, depending on your sw stack, a similar concept could be implemented. If you give me more context on why you are interested in the feature I can try to create a dedicated snippet for you 😃

@vakker
Copy link
Contributor

vakker commented Sep 14, 2020

@g-gemignani thanks for the info, that sounds cool!
I was thinking something like:

from multiprocessing import Pool
from pyswip import Prolog

prolog = Prolog()

def exec_query(q):
    return prolog.query(q)

with Pool(3) as p:
    print(p.map(exec_query, ['query_1', 'query_2', 'query_3']))

This uses multiprocessing.Pool, but it could be with ThreadPool as well depending on where the bottleneck is (I guess).

@g-gemignani
Copy link
Contributor Author

As far as I remember, the server is not able to process queries in parallel, the snippet of code is there just to allow to be called by different threads but it should still be in sequence. We have implemented a master slave node that processes queries in order. Try it out and see :)

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

Successfully merging this pull request may close these issues.

3 participants