Can logging or print methods switch greenlets?

1k views Asked by At

I am still new to greenlets and gevent, but from what I understand, greenlets yield to other greenlets either on an explicit yield statement, or on a blocking I/O operation. But are writes to stdout using a print statement blocking? And what about using the logging module to write to stdout, stderr, or a file on a local disk, or NFS?

Can a call to a print statement or a logging method cause a greenlet switch?

1

There are 1 answers

3
Alex On BEST ANSWER

print statement is always blocking and will not switch to other greenlets. Avoid print instructions in any Gevent server code.

Newer Gevent versions have asynchronous file I/O gevent.os.tp_read that could be used with logging module to achieve non blocking operation. In this case log statements will cause Greenlet context switch.