Provide explicit ways to prevent concurrency

I think this is a bad idea. Moreover, I think this, along with the referenced discussion, miss a couple of important points:

  1. Python is a synchronous language. Generally speaking, your program is executed one statement at time, in order, which makes it easy to reason about correctness, particularly for beginning programmers. Anvil, via the underlying compiler, Skulpt, bends over backwards to preserve this characteristic, while compiling your code into JavaScript–a non-blocking asynchronous language in which things can easily happen out of order, causing endless problems.

  2. Any flaws in this approach which bleed through (such as UI events being triggered while a server call is running) are a result of the nature of the underlying environment, not Anvil, and we should work to prevent those problems intruding into the orderly world of Python, not the other way around.

It’s sometimes useful to have multiple things running, or waiting, at the same time, but this is very hard to get right, as anyone who’s built a non-trivial JavaScript application (or a multi-threaded Realtime application) knows. Yet most applications don’t need concurrency, most of the time.

I’ve built several production applications in Anvil, some with custom JavaScript libraries that talk to external services (like Google Firebase) from the front end. In all cases we flatten out the concurrency in JavaScript wrappers, so the app behaves in a predictable, easy-to-understand manner. If UI events could cause concurrency problems while a server call is running, we simply block that by disabling the component, or by setting a flag.

In cases where you don’t want to wait, more sophisticated approaches are possible. You can achieve pseudo-concurrency in Anvil any time using JavaScript, which you can call into, and out of, at will, in Anvil. Remember, under hood, once it’s running, it’s all JavaScript. But why on earth would you want to open up this can of worms in Anvil, by default?

No offense intended to anyone, love you all, YMMV. I just really hate worrying about concurrency in a data processing app. :frowning:

John

3 Likes