Skip to content

ianchen-tw/trio-vis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trio-vis

trio-vis is a plugin for visualizing the scope history of your Trio project.

showcase

How to use

  1. Install trio-vis via pip install trio-vis (trio-vis-pip)

  2. In your source code, register SC_Monitor() as an Instrument while running trio

    from trio_vis import SC_Monitor
    trio.run(my_main_funciton, instruments=[SC_Monitor()])
  3. After your program finished(or exited), the scope history would be stored in ./sc-logs.json

  4. Upload your log file to sc-visualizer, this is a twin project which focuses on visualization work.

  5. See your visualization result and help us improve.

Configuration

Import VisConfig from trio_vis, and provide it as an argument while making your SC_Monitor object.

from trio_vis import SC_Monitor, VisConfig
cfg = VisConfig(print_task_tree=True)
trio.run(my_main_funciton, instruments=[SC_Monitor(config=cfg)])

What does it do

trio-vis utilize the Instrument API to monitor the lifetime of scopes (Task,Nursery). Since the Instrument API doesn't provide callbacks for Nursery, we make inferences on our own.

Why visualize

Derived from curio, trio combines the idea of Structured Concurrency with existing single-threaded event-driven architecture. Which does make concurrent programs more manageable.

To make trio comparable with curio, contributors of trio also want to mimic the feature of curio-monitor to monitor the current system running state. This idea could be traced back to trio-issue-413.

Since then, projects have been developed (shown below).

However, trio is not curio, at least lifetimes of scopes are structured by nature. I argue that by utilizing the feature of Structured Concurrency, we could visualize programs better. Developers could easily conceptualize their program, and bring their developing experience to the next level.

Previous work

Future plan

This project is in an early developing stage. Stay tuned for future update.