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).
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
Pages: 8
(incl. VAT)