a question regarding multiple threading of pyDatalog

68 views
Skip to first unread message

cai xuejun

unread,
Jan 29, 2016, 11:01:14 AM1/29/16
to pyDatalog
Hi,

I am using pyDatalog in one application, in which there is one main thread, and many multiple threads created dynamically. The main thread will make some datalog queries periodically.  I am wondering if it is possible to let other dynamic created thread to modify pydatalog clauses or statements, and save these changes into the original logic of the main thread. I tried the Logic() method as mentioned in pyDatalog() tutorial, but failed. And I also noticed the tutorial mentioned it is not thread-safe for such write-back operation. Do you know if there is any method to do that?

Br,
Xuejun Cai 

Pierre Carbonnelle

unread,
Jan 29, 2016, 12:42:09 PM1/29/16
to pyDatalog
Hi Xuejun Cai,

Unfortunately, I don't know a method to do that.

The reason is that the main thread may be in the middle of a query resolution when a dynamic thread changes a clause. It's like changing a python program while it is running : scary.

Now, if you can make sure that no queries are currently run in the main thread when you change statements, you have a better chance to have it work. But no garantee though.

Thank you for your message anyway.
PC

Pierre Carbonnelle

unread,
Jan 30, 2016, 5:23:13 AM1/30/16
to pyDatalog
If you really want to go ahead, you could prevent simultaneous access to the list of clauses using locks. You would need to adapt pyEngine.py and Logic.py. I can provide some more hints if you want. I'd appreciate if you could submit your code as improvement to pyDatalog.

See e.g. http://stackoverflow.com/questions/10525185/python-threading-how-do-i-lock-a-thread

Pierre C.

Xuejun Cai

unread,
Feb 1, 2016, 11:33:16 AM2/1/16
to pyDatalog
Hi Pierre,

Thanks for your reply.
I did a test, it does work. But as you mentioned, there is risk when a query is performed in main thread when the datalog statements are changed.
So I am thinking to lock the changing when there is active query in main thread.

Br,
Xuejun

Xuejun Cai

unread,
Feb 1, 2016, 11:33:32 AM2/1/16
to pyDatalog
Hi Pierre,

Thanks for the information. If I made any modification on code of pyDatalog, it will be my pleasure to submit it to you. But at this moment, I will try to modify our code firstly to prevent simultaneous query and changing.

Br,
Xuejun
Reply all
Reply to author
Forward
0 new messages