Hi,
What you describe is asynchronous programming. It has nothing to do with multithreading or multiprocessing per-se, that's just two possibilities. Evennia has chosen a third approach: asynchronous tasks. Basically when you execute a single command it creates a task and does wait for it to process, but others can enter commands. Or to take another example: going on the Evennia webserver and logging at the same time on telnet does use asynchronous operations (but not multithreading or multiprocessing)? How dies it work? It's actually a bit complicated to explain in a single post, but if you want to research the topic, Evennia uses twisted, and twisted's handle of tasks through callbacks is probably what you want to do. There are times when multithreading or multiprocessing is indeed necessary. You'll have to decide whether overcoming the obstacles these two techniques throw at you are worth using them instead of the integrated callback systems.
Now that Evennia has migrated toward Python 3.7 though, notice that asynchronous handling has been integrated, not in Evennia, but in Python itself, though the await and async keywords. In the situation you described, you would have a function calling await on a "long" task, executing it won't block the rest of Evennia (assuming the task operates on asynchronous principles) and when the task is ready, the lines after your "await" will be called. Python does this through a subtle (and a bit surprising) use of generators. Using this syntax in Evennia is still a bit tricky, though Twisted does offer a way to "transform" coroutines into callbacks. Before rushing toward multithreading and multiprocessing, I'll highly encourage you look further into that, it makes code so much easier to write, read and bugs harder to get past, in contrast to multithreaded or multiprocessed applications. If you are willing to read a long tutorial/introduction, I'll warmly recommend this one: https://realpython.com/async-io-python/ . It's long, but it's thorough on the subject.
Otherwise, yeah, if you plan well and feel you have to, I think you can generate either threads or processes from Evennia, nothing prevents you from doing that. I tend to avoid this alternative because, although it looks incredibly simple, it actually leads to a lot of errors and hard-to-debug situations. I much prefer async to that! Personal preference of mine.
HTH,
Vincent-lg
--
You received this message because you are subscribed to the Google Groups "Evennia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to evennia+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/evennia/0d8e8c08-110b-4501-8240-1692a2f04be9%40googlegroups.com.