Results 1 to 7 of 7

Thread: Is http request a blocking call?

  1. #1
    Basic Member
    Join Date
    Dec 2016
    Posts
    76

    Is http request a blocking call?

    It does not seem to be a blocking call as the output of console.
    If it is not a blocking call,how to make a blocking http request? spin lock is not working in lua.
    A blocking call of http request is very important to the correctness of my algorithm!!!.
    https://github.com/lenLRX/Dota2_DPPO_bots ----My ML bot work in progress

  2. #2
    Basic Member
    Join Date
    Mar 2012
    Posts
    2,017
    It is an async call doing its job on a separate thread, therefore it is not blocking. Blocking would basically hang your bot, which means that in a ML scenario, if your bot had shadow blade and all 5 enemies would attack him, by the time your halted execution would resume (i.e. you received a HTTP response) to tell the bot to use shadow blade he'd die.
    If you really want to halt execution, I guess you can try a sleep call but I don't recommend it. If the call is missing you can try a pseudo-infinite while loop until resuming execution. Keep in mind it may freeze the game or the other bots since the VM is shared across the team.

    I assume what you are looking for is a synchronous call not a blocking call.
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  3. #3
    Basic Member
    Join Date
    Dec 2016
    Posts
    76
    Quote Originally Posted by The Nomad View Post
    It is an async call doing its job on a separate thread, therefore it is not blocking. Blocking would basically hang your bot, which means that in a ML scenario, if your bot had shadow blade and all 5 enemies would attack him, by the time your halted execution would resume (i.e. you received a HTTP response) to tell the bot to use shadow blade he'd die.
    If you really want to halt execution, I guess you can try a sleep call but I don't recommend it. If the call is missing you can try a pseudo-infinite while loop until resuming execution. Keep in mind it may freeze the game or the other bots since the VM is shared across the team.

    I assume what you are looking for is a synchronous call not a blocking call.
    There is no "sleep" in lua and pseudo-infinite while loop will freeze the VM forever.
    maybe i should use seq number to solve the problem.
    https://github.com/lenLRX/Dota2_DPPO_bots ----My ML bot work in progress

  4. #4
    Basic Member
    Join Date
    Mar 2012
    Posts
    2,017
    Well, I am not sure what you are trying to achieve since you didn't offer any details other than "you need a blocking call"
    It wouldn't freeze it forever, since it's not an infinite loop. It'd be with a counter since that's how sleep is simulated where the implementation is missing. But as I said, I don't recommend it.
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  5. #5
    Basic Member
    Join Date
    Dec 2016
    Posts
    76
    Quote Originally Posted by The Nomad View Post
    Well, I am not sure what you are trying to achieve since you didn't offer any details other than "you need a blocking call"
    It wouldn't freeze it forever, since it's not an infinite loop. It'd be with a counter since that's how sleep is simulated where the implementation is missing. But as I said, I don't recommend it.
    for example:
    what i want is
    state1->action1->state2->action2......
    but now it may
    state1->state2->action1->action2(override action1)

    i want to make sure i take an "action1" at "state1" and result in "state2"
    https://github.com/lenLRX/Dota2_DPPO_bots ----My ML bot work in progress

  6. #6
    Basic Member
    Join Date
    Mar 2012
    Posts
    2,017
    Don't threads and coroutines do what you want? Not sure if they are included in the DOTA Lua API though.
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  7. #7
    Basic Member axetion's Avatar
    Join Date
    Jan 2017
    Posts
    40
    Quote Originally Posted by The Nomad View Post
    Don't threads and coroutines do what you want? Not sure if they are included in the DOTA Lua API though.
    Lua doesn't expose any machinery for working with threads. In its perfect world, all well-behaved Lua programs are single threaded and use coroutines for their multitasking needs. Of course, most C APIs then use native threads in some capacity, which is where problems occur...

    CreateHTTPRequest uses, for all intents and purposes, a native thread to send the request and run the callback. It's possible it's a green thread running off of CServerGameDLL::GameFrame, but what matters is that it's a thread outside of Lua's single-threaded world view. What OP wants to do is pause execution of the main thread until the completion of this thread, i.e a simple thread join. The problem is that since Lua is supposed to be single-threaded, pausing a "thread" (coroutine) doesn't make any sense -- since there's only supposed to be one thread, there would be no one else to wake it up. The way coroutines work, then, is that they *yield* execution to another coroutine, so that exactly one coroutine is running at any given time. It's not possible to set up some coroutine logic in this scenario so that the Lua VM goes to sleep until resumed by another thread that is basically hidden from it. The main thread must be running something. (Additionally, I'd be surprised if resuming a coroutine in a different thread from where it yielded didn't corrupt either the thread or the coroutine's stack in some way. It's really not built for interacting with real threads.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •