You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Stéphane Thibaud <sn...@gmail.com> on 2019/05/19 05:39:18 UTC

Multithreading using pyignite

Hello Ignite users,

I am wondering whether the pyignite library is thread-safe. I get strange
errors when I try to run the below script. I cannot find anything about
threads in the docs at
https://apache-ignite-binary-protocol-client.readthedocs.io/en/latest/ .
Should I use the library in a different way or is multithreading simply not
supported?

from threading import Thread

import pyignite

IGNITE_PORT = 10800
WEB_HOST = '127.0.0.1'
DB_CLIENT = pyignite.Client()
DB_CLIENT.connect(WEB_HOST, IGNITE_PORT)


test_cache = DB_CLIENT.get_or_create_cache("test_cache")
test_cache.put("a", "b")
for _ in range(1000):
    Thread(target=lambda: print(test_cache.get("a"))).start()


Kind regards,

Stéphane Thibaud

Re: Multithreading using pyignite

Posted by Stéphane Thibaud <sn...@gmail.com>.
Great. Thank you. I went with an awesome pip package called 'resource-pool'.

Kind regards,

Stéphane Thibaud

2019年5月20日(月) 15:44 Ilya Kasnacheev <il...@gmail.com>:

> Hello!
>
> I guess the recommendation here is to create a new client in every thread
> where you need them.
>
> Regards,
> --
> Ilya Kasnacheev
>
>
> вс, 19 мая 2019 г. в 08:39, Stéphane Thibaud <sn...@gmail.com>:
>
>> Hello Ignite users,
>>
>> I am wondering whether the pyignite library is thread-safe. I get strange
>> errors when I try to run the below script. I cannot find anything about
>> threads in the docs at
>> https://apache-ignite-binary-protocol-client.readthedocs.io/en/latest/ .
>> Should I use the library in a different way or is multithreading simply
>> not supported?
>>
>> from threading import Thread
>>
>> import pyignite
>>
>> IGNITE_PORT = 10800
>> WEB_HOST = '127.0.0.1'
>> DB_CLIENT = pyignite.Client()
>> DB_CLIENT.connect(WEB_HOST, IGNITE_PORT)
>>
>>
>> test_cache = DB_CLIENT.get_or_create_cache("test_cache")
>> test_cache.put("a", "b")
>> for _ in range(1000):
>>     Thread(target=lambda: print(test_cache.get("a"))).start()
>>
>>
>> Kind regards,
>>
>> Stéphane Thibaud
>>
>

Re: Multithreading using pyignite

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

I guess the recommendation here is to create a new client in every thread
where you need them.

Regards,
-- 
Ilya Kasnacheev


вс, 19 мая 2019 г. в 08:39, Stéphane Thibaud <sn...@gmail.com>:

> Hello Ignite users,
>
> I am wondering whether the pyignite library is thread-safe. I get strange
> errors when I try to run the below script. I cannot find anything about
> threads in the docs at
> https://apache-ignite-binary-protocol-client.readthedocs.io/en/latest/ .
> Should I use the library in a different way or is multithreading simply
> not supported?
>
> from threading import Thread
>
> import pyignite
>
> IGNITE_PORT = 10800
> WEB_HOST = '127.0.0.1'
> DB_CLIENT = pyignite.Client()
> DB_CLIENT.connect(WEB_HOST, IGNITE_PORT)
>
>
> test_cache = DB_CLIENT.get_or_create_cache("test_cache")
> test_cache.put("a", "b")
> for _ in range(1000):
>     Thread(target=lambda: print(test_cache.get("a"))).start()
>
>
> Kind regards,
>
> Stéphane Thibaud
>