Hi, I have some code that I know is not posix-thread safe. I'm calling it in a celery task, and I have configured celery to use gevent concurrency. This particular section of code doesn't do any blocking IO, but I'm getting errors that look like my it's getting preempted, which suggests multiple OS threads.
After some investigation, I found that my celery worker typically has from 4 to 7 OS threads, and these threads appear to be getting created by gevent (via ThreadPool). It looks like there's a pool size of 10 by default. So I think this is why I'm having issues. I can fix this piece of code, but it raises a bigger question for me.
I've been reading up on everything I can find about this, and I found this github issue[1] which states"
the simplification that gevent offers is that, unlike threading.Thread, a switch to a different greenlet can only occur when specific API calls to gevent are made, instead of at any arbitrary time. So if you "know" that no such API call can happen during a compound operation, you can elide the locks
But if there can be up to 10 OS threads by default, doesn't this mean that I can't avoid locks in those situations? In other words, doesn't all code intended to be run with gevent need to be thread-safe, regardless of whether it contains IO statements?
Thanks!