VisPy Sinewave Demo

VisPy is quite an interesting tool.  They say it is for “scientific visualization”.  Here is an example of that.  I took a demo from their github page and added a little code to generate a sinewave.  The cool thing is that the graph, scaling, panning, zooming, and redrawing all come out of the box.

I previously wrote about installing VisPy.  Thanks to the great efforts of some unnamed people, Python on Windows is really working nicely now.

Here is a screenshot:


Here is the code:

Installing VisPy on Windows 10

VisPy is a Python library for interactive scientific visualization that is designed to be fast, scalable, and easy to use.

Here is how I installed it:

First I installed the latest Python 3.6 on Windows 10 by following the directions on  Once this was installed, I opened up Windows PowerShell and ran this command:

py -m pip upgrade vispy PyQt5 --user

I found some sample code here, and using NotePad++, copied and pasted it, saving it to Desktop\Code\

In PowerShell, I changed to the directory that I saved the python code to and ran it:

cd Desktop\Code
py .\

Here is the output:


It’s a pretty smooth and clean looking UI.  It seems extremely powerful, but I’ll need to dig in and see what makes it tick…

2D Sine Wave Example Using PyOpenGL

Here is an example of a moving 2D sine wave using Python 3, PyGame, and PyOpenGL.  See a  for how to install them.


This sample program is designed to have a 100×60 unit working area with a 10 unit buffer around the edges.  You can see the axis in the lower-left (0,0) where Y+ is up, and X+ is to the right.

The structure of the program was created to make it super easy to work on the “guts” of the graphics without getting it confused with the “bookkeeping” end of OpenGL or PyGame.

Note: the glOrtho() command is how 2D “parallel perspective” is setup.  It defines the left, right, bottom, top, near plane, and far plane.  Because it is parallel, there is not the notion of a “camera” per-se, but rather section of the plane that should be viewed.  Documented here:

Here is the code!

PyGame and OpenGL on Windows 10

First I went to and downloaded the latest version of Python for windows.  I made sure to select the option to add it to the system path.

Then I opened windows PowerShell (just a nicer term)

py -m pip install pygame --user
py -m pip install numpy --user
py -m pip install pyopengl --user

(I also installed NoteTab++, a nice text editor)

From there, I went to github and copied one of the examples from and saved it on my desktop as

In PowerShell, you just type:

cd Desktop
py -m myglcube

Here is my example:


(here is the code)



Python 3 bytes indexing returns integers!

While converting a bunch of werkzeug code to Python 3.1, I ran into an issue with one of the bytes objects that was previously a string.

The line of code in question was originally this:

if value and value[0] == value[-1] == b'"':

If value is something, and the first and last characters are a quote character, then…

However, as it turns out, the bytes object is actually a list of integers in the range of 0-255.

So when you use an indexing operation on a byte, you actually get an integer back. For example:

>>> x = b'Hello World'
>>> x[0]

>>> x = 'Hello World'
>>> x[0]

Big difference, eh?

Python 3.1 and mod_wsgi performance notes

We’re researching the use of Python and mod_wsgi running under apache for developing some extensive web applications.  Here are some notes on a performance test that we recently ran.

Python 3.1.1
mod_wsgi 3.0c5
apache 2.2
RHEL 5.3
quad core xenon
8 GB ram

Development system – not in production use.


1 import time
3 def application(environ, start_response):
4     status = ‘200 OK’
6     output = “hello world!”
8     #time.sleep(1)
10     response_headers = [
11         (‘Content-type’, ‘text/plain’),
12         (‘Content-Length’, str(len(output))),
13         ]
15     start_response(status, response_headers)
17     return [output]

Apache Configuration:

WSGISocketPrefix run/wsgi
<VirtualHost *>
DocumentRoot /home/jason/Code/ShankProject/Web
WSGIScriptAlias /Admin /home/jason/Code/ShankProject/WSGI/
WSGIDaemonProcess threads=15


# Baseline with one process and 15 threads
# 15 threads total

no process definition

WITHOUT time.sleep(1)
concurrency = 1  >> 1800 / second
concurrency = 100 >> 3900 / second

WITH time.sleep(1)
concurrency = 1  >> 1 / second
concurrency = 100  >> 14 / second

# Get a marginal improvement by doubling the threads to 30
# 30 threads total

no process definition

WITHOUT time.sleep(1)
concurrency = 1  >> 1680 / second
concurrency = 100 >> 3500 / second

WITH time.sleep(1)
concurrency = 1  >> 1 / second
concurrency = 100  >> 30 / second

# Take processes from 1 to 3
# 90 threads total


WITHOUT time.sleep(1)
concurrency = 1  >> 1770 / second
concurrency = 100 >> 3500 / second

WITH time.sleep(1)
concurrency = 1  >> 1 / second
concurrency = 100  >> 88 / second

# Take processes from 3 to 6
# Take threads from 30 to 15
# 90 threads total


WITHOUT time.sleep(1)
concurrency = 1  >> 1550 / second
concurrency = 100 >> 3300 / second

WITH time.sleep(1)
concurrency = 1  >> 1 / second
concurrency = 100  >> 88 / second


mod_wsgi performance is outstanding.  Even running slower requests, it
can still handle significant concurrency in daemon mode without any
apparent issues.

Is there any information on the balance between more processes less
threads and more threads less processes?