Channels + steam(gevent based package)

48 views
Skip to first unread message

Lada B

unread,
Mar 7, 2017, 12:06:34 PM3/7/17
to Django users
I'm using 


and I'm trying to make them work together. Problem is that when SteamClient starts I cannot send any message with channels.

Group(group_name).send({
   'text': json.dumps({
         'match_status': "balancing teams",
    }),
})

This won't ever send message until SteamClient is running unless I put it to new thread. But when i do that I end up with: 


gevent.hub.LoopExit: ('This operation would block forever', <Hub at 0x7fc465aabd58 epoll pending=0 ref=0 fileno=27>)


Example of my code:

@client.on('logged_on')
    def start_dota():
        Group(group_name).send({
            'text': json.dumps({
                    'bot': getSteamProfile(str(client.steam_id)),
             }),
         })

        dota.launch()
        dota.wait_event('lobby_removed')

I'm trying to solve this for month already and I still cannot find out how. I just want to run gevent based SteamClient after i call it from main thread. I tried a lot, run it as new process, thread, for example:

p = Thread(target=start_bot, args=(kwargs['instance'].match_id, group1, group2,group_name, rad_reward, dire_reward, team1, team2, ))
p.start()

When I start it as new thread I also get end up with gevent.hub.LoopExit: ('This operation would block forever', ........

or

start_bot(kwargs['instance'].match_id, group1, group2,group_name, rad_reward, dire_reward, team1, team2)

this doesn't send channels messages at all.

Could anyone help me to solve this puzzle? I'm desperate.


Andrew Godwin

unread,
Mar 7, 2017, 6:08:39 PM3/7/17
to django...@googlegroups.com
Where are you running this steam client from? Presumably not a webserver process, as that doesn't have a main thread. Could you explain a bit more about the architecture and what channel layers you have configured?

Andrew

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f6c574c4-3449-4d95-be78-2db3451fcc3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Lada B

unread,
Mar 7, 2017, 6:43:41 PM3/7/17
to Django users
I call it in signal function after enough of user rows is in DB:

@receiver(post_save, sender=chat_session)
def on_create_users_online(sender, created, **kwargs):
    ....
    some magic and conditions
    ....

    start_bot(kwargs['instance'].match_id, group1, group2,group_name, rad_reward, dire_reward, team1, team2)

and in steam.py file:

def start_bot(match, group1, group2, group_name, rad_reward, dire_reward, team1, team2):

    client = SteamClient()
    client.set_credential_location("steam_credentials")
    dota = Dota2Client(client)

    ....
    some code
    ....

    @client.on('logged_on')
        def start_dota():
            Group(group_name).send({
                'text': json.dumps({
                    'bot': getSteamProfile(str(client.steam_id)),
                }),
              })

           dota.launch()
           dota.wait_event('lobby_removed')
    .....
    a lot of events and code
    .....


    client.connect()
    client.run_forever()
    

I will try to describe entire process...so:
User connects to websocket and after they are added to group. All users in group are saved to DB chat_session table.
Once enough users is connected to same group then steam client is started in signal function above.
Then mess I explained above starts to happen.
Even tho steam client is working properly, channels are not and daphne crashes because of block forever errors and backpressure.

Dne úterý 7. března 2017 19:08:39 UTC+1 Andrew Godwin napsal(a):
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Andrew Godwin

unread,
Mar 7, 2017, 6:45:36 PM3/7/17
to django...@googlegroups.com
So you are starting a steam client from a consumer inside a worker process then? Inside a consumer, send() calls will not finish until you return control from the consumer, so maybe that's it?

On Tue, Mar 7, 2017 at 10:39 AM, Lada B <lada...@gmail.com> wrote:
I call it in signal function after enough of user rows is in DB:

@receiver(post_save, sender=chat_session)
def on_create_users_online(sender, created, **kwargs):
    ....
    some magic conditions
    ....


start_bot(kwargs['instance'].match_id, group1, group2,group_name, rad_reward, dire_reward, team1, team2)
    
I will try to describe entire process...so:
User connects to websocket and after they are added to group. All users in group are saved to DB chat_session table.
Once enough users is connected to same group then steam client is started in signal function above.
Then mess I explained above starts to happen.
Even tho steam client is working properly, channels are not and daphne crashes because of block forever errors and backpressure.




Dne úterý 7. března 2017 19:08:39 UTC+1 Andrew Godwin napsal(a):
Where are you running this steam client from? Presumably not a webserver process, as that doesn't have a main thread. Could you explain a bit more about the architecture and what channel layers you have configured?

Andrew

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Lada B

unread,
Mar 7, 2017, 6:50:31 PM3/7/17
to Django users
Do you have some advice? How should I start it and still be able to send all needed parameters there and use channels send()? When I start new Thread it still throws errors and when I start new Process then its broken and there i some fork error in the end.

Dne úterý 7. března 2017 19:45:36 UTC+1 Andrew Godwin napsal(a):

Andrew Godwin

unread,
Mar 7, 2017, 7:24:59 PM3/7/17
to django...@googlegroups.com
I'm afraid I can't really help with something this complex, it seems like your problems stem a lot from gevent and process management as well, and that's a very difficult topic. My general advice would be to try splitting things up into more separate processes (django management commands can be good for this) if possible.

Andrew

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages