All Projects → tiagocoutinho → Gtools

tiagocoutinho / Gtools

Licence: mit
gevent tools

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Gtools

Java Diff Utils
Diff Utils library is an OpenSource library for performing the comparison / diff operations between texts or some kind of data: computing diffs, applying patches, generating unified diffs or parsing them, generating diff output for easy future displaying (like side-by-side view) and so on.
Stars: ✭ 670 (+9471.43%)
Mutual labels:  tools
Vue.d3.tree
Vue component to display tree based on D3.js layout.
Stars: ✭ 726 (+10271.43%)
Mutual labels:  tree
Blink
A tool which allows you to edit source code of any MSVC C++ project live at runtime
Stars: ✭ 808 (+11442.86%)
Mutual labels:  pdb
Pdbpp
pdb++, a drop-in replacement for pdb (the Python debugger)
Stars: ✭ 693 (+9800%)
Mutual labels:  pdb
Pdb Tutorial
A simple tutorial about effectively using pdb
Stars: ✭ 720 (+10185.71%)
Mutual labels:  pdb
Redteamtools
记录自己编写、修改的部分工具
Stars: ✭ 752 (+10642.86%)
Mutual labels:  tools
Allsketchs
Processing sketches, in which I have worked in the last years; images, videos, prototypes, experiments, tools, works, concepts... Everything is unfinished, some may not work, When I had no ideas, I would open one to see what it was...
Stars: ✭ 666 (+9414.29%)
Mutual labels:  tools
Svn2git.php
Subversion to Git migration tool
Stars: ✭ 6 (-14.29%)
Mutual labels:  tools
Coc Explorer
📁 Explorer for coc.nvim
Stars: ✭ 722 (+10214.29%)
Mutual labels:  tree
Raygui
A simple and easy-to-use immediate-mode gui library
Stars: ✭ 785 (+11114.29%)
Mutual labels:  tools
Awesome Transit
Community list of transit APIs, apps, datasets, research, and software 🚌🌟🚋🌟🚂
Stars: ✭ 713 (+10085.71%)
Mutual labels:  tools
React Ui Tree
React tree component with drag & drop
Stars: ✭ 720 (+10185.71%)
Mutual labels:  tree
Aoe
AoE (AI on Edge,终端智能,边缘计算) 是一个终端侧AI集成运行时环境 (IRE),帮助开发者提升效率。
Stars: ✭ 759 (+10742.86%)
Mutual labels:  tools
Dsa.js Data Structures Algorithms Javascript
🥞Data Structures and Algorithms explained and implemented in JavaScript + eBook
Stars: ✭ 6,251 (+89200%)
Mutual labels:  tree
Atscan
Advanced dork Search & Mass Exploit Scanner
Stars: ✭ 817 (+11571.43%)
Mutual labels:  tools
Vue Org Tree
A simple organization tree based on Vue2.x
Stars: ✭ 670 (+9471.43%)
Mutual labels:  tree
Ics Security Tools
Tools, tips, tricks, and more for exploring ICS Security.
Stars: ✭ 749 (+10600%)
Mutual labels:  tools
Nexer
Content based network multiplexer or redirector made with love and Go
Stars: ✭ 7 (+0%)
Mutual labels:  tools
Echo
Echo是一款桌面端调试工具,旨在提高客户端的研发调试效率
Stars: ✭ 818 (+11585.71%)
Mutual labels:  tools
Apidoc
RESTful API 文档生成工具,支持 Go、Java、Swift、JavaScript、Rust、PHP、Python、Typescript、Kotlin 和 Ruby 等大部分语言。
Stars: ✭ 785 (+11114.29%)
Mutual labels:  tools

gtools

A python library providing gevent tools:

  • a gevent friendly pdb
  • tree representation of running greenlets

Gevent friendly pdb

The standard python pdb module blocks all greenlets at the pdb prompt (unlike a threaded app). If you want your greenlets to run in the background you can use gtools.pdb instead.

It can be used like the standard pdb.

So, imagine you have a gevent app that you want to debug:

# ======
# app.py
# ======

import gevent

def produce(p):
    for i in range(60):
        p.append(i)
        gevent.sleep(1)

products = []
gevent.spawn(produce, products)

to debug it just type on the console:

$ python -m gtools.pdb app.py

Then hit 'n' until you reach the task.join() line. At this point the greenlet is already doing its work on the background. To make sure just type products several times on the pdb console and you will see the products list being filled by the running greenlet:

> /app.py(9)<module>()
-> gevent.spawn(produce, products)
(Pdb) products
[0, 1, 2]
(Pdb) products
[0, 1, 2, 3, 4, 5, 6, 7]

Use gtools.pdb.set_trace() just as you would with the standard pdb.set_trace()

Monitoring greenlets

gtools.tree.Tree() allows you to trace the current greenlets and display them in a tree like structure:

>>> import gevent
>>> import gtools.tree

>>> def iloop():
...     gevent.sleep(1)

>>> def oloop():
...     gtools.spawn(iloop)
...     gevent.sleep(0.5)

>>> task = gtools.spawn(oloop)

>>> # sleep just to trigger spawn of inner greenlets
>>> gevent.sleep()
>>> tree = gtools.tree.Tree()

>>> # initial status
>>> print(tree)
Root
└─ <greenlet.greenlet A> status=running
    └─ <Greenlet B: oloop> status=running
        └─ <Greenlet C: iloop> status=running

>>> # after outer loop finishes
>>> gevent.sleep(0.6)
>>> print(tree)
Root
└─ <greenlet.greenlet A> status=running
    └─ <Greenlet B: oloop> status=finished:success
        └─ <Greenlet C: iloop> status=running

>>> # after inner loop finishes
>>> gevent.sleep(0.6)
>>> print(tree)
Root
└─ <greenlet.greenlet A> status=running
    └─ <Greenlet B: oloop> status=finished:success
        └─ <Greenlet C: iloop> status=dead:garbage collected

>>> del task

>>> # when there are no more references to the greenlets
>>> print(tree)
Root
└─ <greenlet.greenlet A> status=running
    └─ <Greenlet B: oloop> status=dead:garbage collected
        └─ <Greenlet C: iloop> status=dead:garbage collected

>>>
>>> # new tree
>>> print(gtools.tree.Tree())
Root

The above example requires the usage of gtools.Greenlet.

To trace greenlets from an existing gevent application you simply need to monkey-patch gevent itself before importing your app:

# ======
# app.py
# ======

import gevent

def iloop():
    gevent.sleep(1)

def oloop():
    gevent.spawn(iloop)
    gevent.sleep(0.5)

def run():
    return gevent.spawn(oloop)
>>> from gtools.monkey import patch_gevent
>>> patch_gevent()
>>> import app
>>> import gtools.tree

>>> the_app = app.run()

>>> # sleep just to trigger spawn of inner greenlets
>>> gevent.sleep()
>>> tree = gtools.tree.Tree()

>>> # initial status
>>> print(tree)
Root
└─ <greenlet.greenlet A> status=running
    └─ <Greenlet B: oloop> status=running
        └─ <Greenlet C: iloop> status=running

If you don't monkey patch, you can still have limited information about the running greenlets (notice that the tree hierarchy is lost):

>>> import app
>>> import gtools.tree
>>> task = gevent.spawn(oloop)

>>> the_app = app.run()

>>> # sleep just to trigger spawn of inner greenlets
>>> gevent.sleep()
>>> tree = gtools.tree.Tree(all=True)

>>> # initial status
>>> print(tree)
Root
└─ <greenlet.greenlet A> status=running
    └─ <Hub [...]> status=running
        ├─ <Greenlet B: oloop> status=running
        └─ <Greenlet C: iloop> status=running

It can even trace greenlets across multiple threads (see examples/tree_threads.py)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].