Essentially you get to launch a task into the event loop (and the task can itself launch more tasks if it wants) and specify a timeout in seconds; after the timeout period the function returns a tuple with the tasks that are done and the tasks that are still pending. Presumably we could just drop any tasks that take too long on the floor, and never complete them.
@1Bayshore thinks this is likely to require us to decorate or label as async every single function in the game, which would be a huge hassle, but we need to investigate more.
This wouldn't fully prevent rogue or incompetent wizards from crashing the game or slowing it to a crawl, because they could fairly easily write code that spawns a zillion objects and takes up all of memory (or enough to make the system start thrashing), or spawns a zillion more tasks and overwhelms the event loop, but it would help a lot with the most common coding mistakes that a less experienced wizard is likely to make (or sometimes even a very experienced wizard!)
We would also like to detect and prevent memory leaks somehow - no ideas on this yet.
It seems to me that we can use asyncio and waiting primitives to be sure that any wizard code cannot halt the game by going into an infinite loop:
https://docs.python.org/3/library/asyncio-task.html#waiting-primitives
Essentially you get to launch a task into the event loop (and the task can itself launch more tasks if it wants) and specify a timeout in seconds; after the timeout period the function returns a tuple with the tasks that are done and the tasks that are still pending. Presumably we could just drop any tasks that take too long on the floor, and never complete them.
@1Bayshore thinks this is likely to require us to decorate or label as async every single function in the game, which would be a huge hassle, but we need to investigate more.
This wouldn't fully prevent rogue or incompetent wizards from crashing the game or slowing it to a crawl, because they could fairly easily write code that spawns a zillion objects and takes up all of memory (or enough to make the system start thrashing), or spawns a zillion more tasks and overwhelms the event loop, but it would help a lot with the most common coding mistakes that a less experienced wizard is likely to make (or sometimes even a very experienced wizard!)
We would also like to detect and prevent memory leaks somehow - no ideas on this yet.