Is there a limit on asynchronous calls (with utils.run_async) running at once?

50 views
Skip to first unread message

Wontoon Wolf

unread,
Jan 19, 2017, 3:00:25 AM1/19/17
to eve...@googlegroups.com
So I ran into a rather interesting wall. I have a very simple AI script for NPCs currently, and it involves using utils.run_async (if players are in the area, otherwise it doesn't need to run). Upon doing some testing of mob AI, it seems that if I run multiple async calls (it seems to be 10, which seems awfully low) no run_async calls will run.

Likely this will mean that I'll have to try something involving the built in tickers instead (may be doable since there's no touching the database here?), but I feel I must ask: is this a thing in Evennia with how run_async works or with Python in general? I couldn't find any documentation on it in the wiki, so I figured I'd ask.

Griatch Art

unread,
Jan 19, 2017, 3:50:17 AM1/19/17
to Evennia
Hi,

The original use for run_async was to use it with a running process pool (the ampoule system). This meant offloading callbacks to a completely separate process for true parallelism. This implementation had problems with caching and maintainability and its development was halted (if you are interested you can see it in The unworking procpool evennia fork. The current version of run_async uses threads and works great for quick asynchronous returns in commands, not for potentially heavy AI processing, due to the Python GIL. That said, the 10-limit is likely due to the thread pool limit on the default Twisted reactor, which is 10. To up this, you can add the following to mygame/server/conf/at_server_startstop.py;

from twisted.internet import reactor

def at_server_start():
    reactor
.suggestThreadPoolSize(30)


Note, as said, that threading is not a good solution for heavy computing off-loading in Python. You will also have to be very careful about race conditions with your code - especially if you use it to write to the database. For "true" parallelism you should use processes for this, using twisted's spawnProcess. Evennia has no ready solution wrapper for this (maybe we should add something less ambitious than the procpool for this use case).
.
Griatch
Reply all
Reply to author
Forward
0 new messages