Discussing the article: "Market Simulation (Part 13): Sockets (VII)"

 

Check out the new article: Market Simulation (Part 13): Sockets (VII).

When we develop something in xlwings or any other package that allows reading and writing directly to Excel, we must note that all programs, functions, or procedures execute and then complete their task. They do not remain in a loop, no matter how hard we try to do things differently.

In the previous article, "Market Modeling (Part 12): Sockets (VI)", we created a Python server capable of responding to multiple clients. It worked through the use of threads. I believe the core idea of how threads function is now clear. But above all, I hope you were able to understand how the server manages, in a sense, to make a small chat work. The purpose of these explanations about sockets is not to cover everything about them. We want you to understand how sockets work. This knowledge will be needed later in the replay/simulation system.

However, even though the Python server works in such a way that it can be used by multiple clients, it is not designed for use within Excel. That is, if we use xlwings to integrate this server into Excel, you will encounter issues when interacting with Excel. But why, if we are using threads to avoid blocking code execution?

This is a somewhat complex question— at least for those who are not very familiar with how a program uses another program that is not part of it. Perhaps that sentence was a bit confusing, but let's try to understand it. When we use a VBA script inside Excel, we are essentially running a program. If that script calls another application, Excel usually waits for it to finish executing. But this is not always the case. To prevent Excel from having to wait for the application to complete, we can use an application that is not linked to Excel. That is, we would have Excel open alongside another application working with VBA. Both can coexist without competing for the CPU. It is roughly the same as asking Excel to open Word. It doesn't matter if Word freezes—that won't interfere with Excel's operation.


Author: Daniel Jose

 
MetaQuotes:

Published article Market Simulation (Part 13): Sockets (VII):

Author: Daniel Jose

Thanks