Multithreading using pyignite

classic Classic list List threaded Threaded
3 messages Options
Stéphane Thibaud-2 Stéphane Thibaud-2
Reply | Threaded
Open this post in threaded view
|

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
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Multithreading using pyignite

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 <[hidden email]>:
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
Stéphane Thibaud-2 Stéphane Thibaud-2
Reply | Threaded
Open this post in threaded view
|

Re: Multithreading using pyignite

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 <[hidden email]>:
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 <[hidden email]>:
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