-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BeamNGpy blocks indefintely while communicating with the simulator #249
Comments
Hi, the current BeamNGpy protocol is designed to be a synchronous request-response protocol, and exposing the timeout would not make the communication strictly better. In the end, there is a single TCP connection maintained between BeamNG and BeamNGpy and all the data need to pass through it anyways. I'm curious whether setting a socket timeout on your side fixed the issues you had? Do you have a concrete example where the timeout can improve the experience? What you could try is to wrap BeamNGpy in Python's built-in process-based parallelism library if you need to do other operations while waiting for the response from BeamNG. |
Here is an example of when having a convenient way to set the timeout is useful: I am running one scenario after the other in an instance of the simulator, it usually works fine, but sometimes I encounter a bug for which after the CreateScenario message, the scenario start overlay goes away, but the timer does not start and the simulator never replies to the python library with the "everything ok" message. In a case like this my program waits forever for the simulator's answer. I could wrap every call to beamngpy in an async function and implement a timeout myself, but that seems like a bad solution. |
Update on this problemI have understood exactly what is happening. It is not a problem of the library or my algorithm, it is most likely a bug of BeamNG.tech. Sometimes, unpredictably, the module of the simulator that handles communication with the library breaks. It always happens when sending the StartScenario message. The server socket inside the simulator is still open, can accept connections, and sends TCP ACKs, but it no longer answers to messages, so the library waits forever. |
Hi, |
Dear BeamNG team,
I am encountering network issues that prevents me from continuing a case study using BeamNG for my research project.
During long experiments that involve loading and simulating various scenarios it often happens that the BeamNGpy library blocks indefintely while sending messages to or waiting acks from the simulator.
I have looked at the source code and I found out that the library communicates with the simulator through the PrefixedLengthSocket class. When the OS socket that is managed by this class is initialized, the timeout is set to None, putting the socket in blocking mode.
I think it would be good practice to let the user of the library handle the timeout for socket operations. It would make sense if I could choose a timeout value while creating the BeamNGpy instance. Then, I would be able to properly handle cases in which the simulator is not responding or some other unforeseen event happens during network communication.
Please let me know if there is any other way to handle this that I have missed.
Thank you for your help.
The text was updated successfully, but these errors were encountered: