8000 Multi threaded use of RCON · Issue #13 · conqp/rcon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Multi threaded use of RCON #13
Open
@gilesknap

Description

@gilesknap

Should RCON be thread safe if you open a new client per thread?

I have been successfully using this but have started to see a few instances of where the response that should go back to thread A is concatenated to the response for thread B, Thread A gets a null response when this happens.

A minimal demo of the issue is here:

import threading
from time import sleep

from mcipc.rcon.je import Client

from mciwb.nbt import parse_nbt


def get_player_pos(name: str, wait: float):
    client = Client("nuc2", port=30555, passwd="spider")
    client.connect(True)
    for i in range(100):
        x = client.data.get(entity="@p", path="Pos")
        print(name, parse_nbt(x))
        sleep(wait)

def go():
    t1 = threading.Thread(target=get_player_pos, args=("t1", 0.2))
    t2 = threading.Thread(target=get_player_pos, args=("t2", 0.3))
    t1.start()
    t2.start()

The results of this test show a clash on the first call to both threads. If I adjust the wait to be the same I see more clashes.

In [1]: go()

Error parsing NBT text: TransformerScorn has the following entity data: [430.74282982933767d, 178.11815687065814d, -1507.2116496515248d]TransformerScorn has the following entity data: [430.74282982933767d, 178.11815687065814d, -1507.2116496515248d] 

 ERROR: Extra data: line 1 column 62 (char 61)
t2 None
t1 [430.74282982933767, 178.11815687065814, -1507.2116496515248]
t1 [430.74282982933767, 178.11815687065814, -1507.2116496515248]
t2 [430.74282982933767, 178.11815687065814, -1507.2116496515248]
t1 [430.74282982933767, 178.11815687065814, -1507.2116496515248]
t1 [430.74282982933767, 178.11815687065814, -1507.2116496515248]
Error parsing NBT text: TransformerScorn has the following entity data: [430.74282982933767d, 178.11815687065814d, -1507.2116496515248d]TransformerScorn has the following entity data: [430.74282982933767d, 178.11815687065814d, -1507.2116496515248d] 

 ERROR: Extra data: line 1 column 62 (char 61)
t2 None
t1 [430.74282982933767, 178.11815687065814, -1507.2116496515248]
t2 [430.74282982933767, 178.11815687065814, -1507.2116496515248]
t1 [430.74282982933767, 178.11815687065814, -1507.2116496515248]
t2 [430.74282982933767, 178.11815687065814, -1507.2116496515248]
0