[CSGO] Gamethread crashes server on give_named_item

Please post any questions about developing your plugin here. Please use the search function before posting!
kalle
Junior Member
Posts: 26
Joined: Sun Jun 26, 2016 9:48 am
Contact:

[CSGO] Gamethread crashes server on give_named_item

Postby kalle » Mon Aug 22, 2016 9:08 am

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.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CSGO] Gamethread crashes server on give_named_item

Postby Ayuto » Mon Aug 22, 2016 10:51 am

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.
kalle
Junior Member
Posts: 26
Joined: Sun Jun 26, 2016 9:48 am
Contact:

Re: [CSGO] Gamethread crashes server on give_named_item

Postby kalle » Mon Aug 22, 2016 11:03 am

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.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CSGO] Gamethread crashes server on give_named_item

Postby Ayuto » Mon Aug 22, 2016 11:57 am

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.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: [CSGO] Gamethread crashes server on give_named_item

Postby BackRaw » Thu Sep 08, 2016 6:28 pm

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.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CSGO] Gamethread crashes server on give_named_item

Postby Ayuto » Thu Sep 08, 2016 6:33 pm

It's called in the thread you created.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: [CSGO] Gamethread crashes server on give_named_item

Postby BackRaw » Thu Sep 08, 2016 6:37 pm

Ayuto wrote:It's called in the thread you created.

Hhhhmmm, how do you call something on the main thread then?
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CSGO] Gamethread crashes server on give_named_item

Postby Ayuto » Thu Sep 08, 2016 8:14 pm

Use the Delay class. :grin:
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: [CSGO] Gamethread crashes server on give_named_item

Postby BackRaw » Sat Sep 10, 2016 3:38 pm

Ah dang. You got me there :D thanks

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 35 guests