Page 1 of 1

[CSGO] Gamethread crashes server on give_named_item

Posted: Mon Aug 22, 2016 9:08 am
by kalle
Hey guys,

I figured out that giving a player a weapon with a gamethread (even if I just proof he is in the team CT or T) the server instantly crashes. Is it a bug on your side or is a gamethread not designed to work with giving named items?

Below is an example that let my server crash everytime I spawn together with some bots. If I spawn alone all is fine. It seems that I can't create multiple instances of the GameThread class for the same function, even if I try to use "name" to give them unique names at all. I don't know if it's a error related to python or sourcepython. As far as I know It should be possible to start the same function multiple times at nearly the same time without any problems (see http://www.saltycrane.com/blog/2008/09/ ... d-example/).

I also managed to get some more information for you: as far as I have tested this error only occurs if I give a player any kind of weapons / named items. All other functions related to the player entity seem to work (however I do not use many different functions of the player entity).

Syntax: Select all

from events import Event
from players.entity import Player
from listeners.tick import GameThread

## working
@Event('player_spawn')
def player_spawn(event):
test(event['userid'])

## not working
#@Event('player_spawn')
#def player_spawn(event):
# t = GameThread(target=test, args=(event['userid'], ))
# t.start()

def test(playerID):
player = Player.from_userid(playerID)
player.give_named_item('weapon_awp', 0, None, True)


Any help would be great. Idea behind using GameThread is that I don't want that stuff to happen directly in the server.ontick process. Because if something in my functions needs some time it will kill the server stability.

Re: [CSGO] Gamethread crashes server on give_named_item

Posted: Mon Aug 22, 2016 10:51 am
by Ayuto
kalle wrote:As far as I know It should be possible to start the same function multiple times at nearly the same time without any problems (see http://www.saltycrane.com/blog/2008/09/ ... d-example/).

Yes, as long as the function is thread-safe. Calling Function.__call__ (it's used internally by give_named_item) is not thread-safe at the moment due to g_pCallVM being used.

kalle wrote:Idea behind using GameThread is that I don't want that stuff to happen directly in the server.ontick process. Because if something in my functions needs some time it will kill the server stability.
What kind of functions are those? Accessing a database or heavy calculations? Those should actually be separated into a thread and not give_named_item. If you separate give_named_item, but not these functions you will still block your server, because you still call the functions from the main thread.

Re: [CSGO] Gamethread crashes server on give_named_item

Posted: Mon Aug 22, 2016 11:03 am
by kalle
Okay thanks for the quick response :)

Is there a possibility that it'll be thread safe in future? These calculations are not very heavy atm but I have to struggle with some test servers sponsored by some guys that even lag on an vanilla 10bot csgo server heavily. So I wanted to deal with that and exclude as many things as possible from the main thread.

And yes, there are database operations included. But that's normally not a performance killer at all at the on spawn function.

Re: [CSGO] Gamethread crashes server on give_named_item

Posted: Mon Aug 22, 2016 11:57 am
by Ayuto
Threading will not give you a performance boost. Especially in not in Python, because it's not able to use multiple CPU cores due to the global interpreter lock.

You better forget the idea of using GameThread for this task.

Re: [CSGO] Gamethread crashes server on give_named_item

Posted: Thu Sep 08, 2016 6:28 pm
by BackRaw
When you call a function from a function which has been executed by GameThread (t.start()), is it called on that thread or the main thread? Kinda OT sorry :D

Edit: Can't I/we write a C++ GameThread lib exposed to Python which utilizes more cores? I haven't done any threading in C++ but it would be a great thing to learn. That however raises the question (for me), if the Thread(ing) module has been written in C++ or not. If yes then it's probably not a good idea to rework it.

Re: [CSGO] Gamethread crashes server on give_named_item

Posted: Thu Sep 08, 2016 6:33 pm
by Ayuto
It's called in the thread you created.

Re: [CSGO] Gamethread crashes server on give_named_item

Posted: Thu Sep 08, 2016 6:37 pm
by BackRaw
Ayuto wrote:It's called in the thread you created.

Hhhhmmm, how do you call something on the main thread then?

Re: [CSGO] Gamethread crashes server on give_named_item

Posted: Thu Sep 08, 2016 8:14 pm
by Ayuto
Use the Delay class. :grin:

Re: [CSGO] Gamethread crashes server on give_named_item

Posted: Sat Sep 10, 2016 3:38 pm
by BackRaw
Ah dang. You got me there :D thanks