Use CherryPy add a web interface to a Python script

Threading vs. Subprocess

In my code, you'll find two methods that run code in other places: Subprocesses and threading. Subprocesses block the program while they run. In my case, I'm accessing the underlying OS functions iwconfig and ifconfig to get network data. Once the command finishes, my program picks up where it left off and I get the output as a string.

Threading does not block; instead, it starts an additional process that runs at the same time as the main program. The two processes share their namespace so that variables and functions can be shared between the two.

Playing the Game

To play the game, navigate to the poker directory then run

sudo python poker.py

After a few seconds, a welcome screen appears (Figure 1). Make sure you are connected to the same network as the Raspberry Pi, then open your web browser and navigate to the provided address. You should be greeted with a join screen (Figure 2).

Figure 1: The join/welcome screen. As players join, their names are listed down the left-hand side of the table on the screen.
Figure 2: The join screen on my phone. Once you enter a nickname, you'll be waiting for the game to start! If you're the dealer, you'll get a Deal! button.

The first player will be the dealer. Once all players are connected to the game, press Deal! and the game begins!

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content