The issue you are having is an old one in programming.? You have two basic choices: polling and interrupting.? Polling means you check a status, usually in a loop with a sleep or yield call.? Interrupting means you wait on an event from the server, usually received as a callback in IB's API.? The interrupting is better but harder to write.? You usually have to add extra logic to implement a timeout in case the server doesn't respond at all.
For what you are doing, polling is likely far better unless you are a pretty good professional programmer with years of experience.? Just wrap a loop around your logic and you are there.? Probably best to make the loop run at most a set number of times.? The max total wait time will be the number of times the loop can run times the length of the sleep.? You probably want to make the max total wait time to be about 15 seconds (5sec to a minute is reasonable).? I hope this helps.
Hunter
On Sunday, October 8, 2023 at 07:21:29 AM PDT, fran <fchiesadoc@...> wrote:
In the interest of helping, Andrew's suggestion is for an interrupt style.? It also has a synchronization bug in it (the blocks of code that reads/writes the flag needs to be in a synch block, them being thread-safe isn't enough because the logic depends on multiple accesses).? And that's my point about doing this in an interrupt style way, its really (really really really) hard to get right.? As in most professional programmers don't attempt this stuff and instead use frameworks that don't require threading or give this type of work to a specialist (read old and expensive) programmer in most situations.? Just do a while loop as I suggested and if you don't want the blocking behavior, launch a thread to send the request and wait on the response (but you probably don't need to do that).? IBApi is really designed to be used in a single-threaded design.
Hunter
On Sunday, October 8, 2023 at 03:33:36 PM PDT, Andrew Bannerman <bannerman1985@...> wrote:
Python if it's python your using - threading.event() module. Can assign different threads to events?
threading.Event is a method to communicate between threads. I find it useful when waiting for a server to respond versus time.sleep() - when we get a server response the flag on the response is .set() (true) and the other threads waiting for it are released.?
On Sun, Oct 8, 2023 at 6:50?PM Hunter C Payne via <hunterpayne2001=[email protected]> wrote:
In the interest of helping, Andrew's suggestion is for an interrupt style.? It also has a synchronization bug in it (the blocks of code that reads/writes the flag needs to be in a synch block, them being thread-safe isn't enough because the logic depends on multiple accesses).? And that's my point about doing this in an interrupt style way, its really (really really really) hard to get right.? As in most professional programmers don't attempt this stuff and instead use frameworks that don't require threading or give this type of work to a specialist (read old and expensive) programmer in most situations.? Just do a while loop as I suggested and if you don't want the blocking behavior, launch a thread to send the request and wait on the response (but you probably don't need to do that).? IBApi is really designed to be used in a single-threaded design.
Hunter
On Sunday, October 8, 2023 at 03:33:36 PM PDT, Andrew Bannerman <bannerman1985@...> wrote:
Python if it's python your using - threading.event() module. Can assign different threads to events?
None of that invalidates anything I said about the code you posted.
Hunter
On Sunday, October 8, 2023 at 06:42:57 PM PDT, Andrew Bannerman <bannerman1985@...> wrote:
threading.Event is a method to communicate between threads. I find it useful when waiting for a server to respond versus time.sleep() - when we get a server response the flag on the response is .set() (true) and the other threads waiting for it are released.?
On Sun, Oct 8, 2023 at 6:50?PM Hunter C Payne via <hunterpayne2001=[email protected]> wrote:
In the interest of helping, Andrew's suggestion is for an interrupt style.? It also has a synchronization bug in it (the blocks of code that reads/writes the flag needs to be in a synch block, them being thread-safe isn't enough because the logic depends on multiple accesses).? And that's my point about doing this in an interrupt style way, its really (really really really) hard to get right.? As in most professional programmers don't attempt this stuff and instead use frameworks that don't require threading or give this type of work to a specialist (read old and expensive) programmer in most situations.? Just do a while loop as I suggested and if you don't want the blocking behavior, launch a thread to send the request and wait on the response (but you probably don't need to do that).? IBApi is really designed to be used in a single-threaded design.
Hunter
On Sunday, October 8, 2023 at 03:33:36 PM PDT, Andrew Bannerman <bannerman1985@...> wrote:
Python if it's python your using - threading.event() module. Can assign different threads to events?