Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gevent monkey unpatch

I'm doing my program in many steps. One of them is to use gevent + monkey patch

from gevent import monkey; monkey.patch_all()

Everything works great. But can i unpatch it after i'm done using it ? I want to return to my default socket functions.

like image 270
artyomboyko Avatar asked Jun 12 '12 03:06

artyomboyko


People also ask

What is gevent monkey patching?

gevent is a coroutine-based cooperative multitasking python framework that relies on monkey patching to make all code cooperative. Gevent actually draws its lineage from Eve Online which was implemented using Stackless Python which eventually evolved into eventlet which inspired gevent.

What is gevent used for?

gevent is a coroutine -based Python networking library that uses greenlet to provide a high-level synchronous API on top of the libev or libuv event loop. Features include: Fast event loop based on libev or libuv. Lightweight execution units based on greenlets.

What does monkey Patch_all () do?

A monkey patch is a way to change, extend, or modify a library, plugin, or supporting system software locally. This means applying a monkey patch to a 3rd party library will not change the library itself but only the local copy of the library you have on your machine.

Why is it called monkey patching?

Etymology. The term monkey patch seems to have come from an earlier term, guerrilla patch, which referred to changing code sneakily – and possibly incompatibly with other such patches – at runtime. The word guerrilla, nearly homophonous with gorilla, became monkey, possibly to make the patch sound less intimidating.


1 Answers

reload(socket)

This blog post has a pretty good write up of the solution here: https://emptysqua.re/blog/undoing-gevents-monkey-patching/

like image 82
Trevor Avatar answered Nov 15 '22 10:11

Trevor