Quantcast
Viewing latest article 17
Browse Latest Browse All 50

Python/gevent equivalent for `go func()` in go

In short, it’s gevent.spawn

In go, where you would write:

go func(arg1, arg2, arg3)

In python/gevent, you would write:

gevent.spawn(func, arg1, arg2, arg3)

This will spawn a greenlet and schedule it to be started. It will execute once the current greenlet yields.

If you’re running in a shell or a one-time script then you need to explicitly yield by calling gevent.sleep(0).

Note that gevent.spawn also accepts keyword arguments (which will be forwarded to the function).


Viewing latest article 17
Browse Latest Browse All 50

Trending Articles