Thread Carefully: An Introduction To Concurrent Python

The ability to execute code in parallel is crucial in a wide variety of scenarios. Concurrent programming is a key asset for web servers, producer/consumer models, batch number-crunching and pretty much any time an application is bottlenecked by a resource.

It’s sadly the case that writing quality concurrent code can be a real headache, but this article aims to demonstrate how easy it is to get started writing threaded programs in Python. Due to the large number of modules available in the standard library which are there to help out with this kind of thing, it’s often the case that simple concurrent tasks are surprisingly quick to implement.

We’ll walk through the difference between threads and processes in a Python context, before reviewing some of the different approaches you can take and what they’re best suited for.

Continue reading “Thread Carefully: An Introduction To Concurrent Python”

Hacker Makes A Flawless Booby Trap, Strikes Back Against Package Thieves

[Mark Rober] was fed up with packages going missing. He kept receiving notifications that his shipments had been delivered, but when checking his porch he found nothing there. Reviewing the CCTV footage revealed random passers-by sidling up to his porch and stealing his parcels. It was time to strike back. Over six months, [Mark] and his friends painstakingly designed, prototyped and iterated the perfect trap for package thieves, resulting in a small unit disguised as an Apple HomePod. The whole scheme is wonderfully over-engineered and we love it.

The main feature of the device is a spinning cup on the top which contains a large amount of glitter. When activated, it ejects glitter in every directions. You could say it’s harmless, as it’s just glitter. But then again, glitter has a way of staying with you for the rest of your life — turning up at the least expected times. It certainly leaves an emotional impression.

Activation is quite clever; the fake package sits on the porch until an accelerometer detects movement. At that point, GPS checks to see if the package has traveled outside a geo-fence around [Mark]’s house. A signal is then sent to the four smartphones to start recording — yes, that’s right, there are 4 phones inside, one on each side to capture the reaction of the thief.

How can [Mark] be so confident that he’ll be able to recover the four phones and their footage? That’s answered by GPS tracking and a can of fart spray actuated by a 3D printed cam and DC motor, ensuring the thief won’t want this package around for long. This actuator and the glitter motor are controlled by a custom PCB, which also triggers the phones to start recording through their headphone jacks and detects the opening of the package with some microswitches. This is truly a masterpiece that outsmarts the package thieves in a way that leaves an impression while still being playful.

(Editor’s Note 2: On 12/20/18 it was announced that two of the five thieves shown in the originally video were staged, apparently without [Mark Rober’s] knowledge. Here is his statement on the matter.)

(Editor’s Note 1: [Sean Hodgins] wrote in with bonus video on how the Glitter Bomb works and how it was made.)

If booby traps are your thing, we’ve got you covered. Check out this ticking bomb style puzzle, or this crate challenge which is rigged to blow.

Continue reading “Hacker Makes A Flawless Booby Trap, Strikes Back Against Package Thieves”

Real Time Satellite Tracker Shows You What’s Going Over Your Head

Whilst modern technology relies heavily on satellites, it’s easy to forget they’re there; after all, it’s hard to comprehend mostly-invisible lumps of high-density tech whizzing around above you at ludicrous speeds. Of course, it’s not hard to comprehend if you’ve built a real-time satellite tracker which displays exactly what’s in orbit above your head at any given time. [Paul Klinger]’s creation shows the position of satellites passing through a cylinder of 200 km radius above the tracker.

Each layer of LEDs represents a specific band of altitude, whilst the colour of the LEDs and text on the screen represent the type of object. The LEDs themselves are good old WS2812b modules, soldered to a custom PCB and mounted in a 3D-printed stand. The whole thing is a really clean build and looks great – you can see it in action in the video after the break

On the software side, a Raspberry Pi is in charge, running Python which makes use of pyorbital for some of the heavy lifting. The data is taken from, who provide a handy API. All the code is on the project GitHub, which also includes the 3D print and PCB files.

[Paul] answers questions in the reddit thread, and gives more detail in this reddit comment. The project was inspired by one of our favorite sites:

Some of the satellites the device displays are de-commisioned and inactive. Space junk is a significant problem, one which can only be tackled by a space garbage truck.

Continue reading “Real Time Satellite Tracker Shows You What’s Going Over Your Head”

E-ink Typewriter Is Refreshingly Slow

It’s pretty hard to use the internet to complete a task without being frequently distracted. For better or worse, there are rabbit holes at every turn and whilst exploring them can be a delight, sometimes you just need to focus on a task at hand. The solution could be in the form of distraction-blocking software, razor-sharp willpower, or a beautifully crafted modern “typewriter”. The constraint and restriction of a traditional typewriter appealed to [NinjaTrappeur], but the inability to correct typos and share content online was a dealbreaker. A hybrid was the answer, with a mechanical keyboard commanding an E-ink display driven by a Raspberry Pi.

The main point of interest in this build is the E-ink screen. Though it’s easy to acquire theses displays in small sizes, obtaining a screen greater than four inches proved to be a challenge. Once acquired, driving the screen over SPI was easy, but the refresh rate was horrific. The display takes three seconds to redraw, and whilst [NinjaTrappeur] was hoping to implement a faster “partial refresh”, he was unable to read the appropriate values from the onboard flash to enable manual control of the drawing stages. Needless to say, [NinjaTrappeur] asks if people have had success driving these displays at a more usable rate, and would love to hear from you if so.

Some auxiliary hacks come in the form of terminal emulator adaptation, porting the E-ink screen library from C++ to C, and capturing the keyboard input. A handmade wooden case finishes it off.

If it’s old-school typewriters that float your boat, we’ve got you covered: this solenoid-actuated typewriter printer eventually became a musical instrument, and this daisy wheel machine produces ASCII art from a live camera.

[Via Boing Boing]

Learn To Loop The Python Way: Iterators And Generators Explained

If you’ve ever written any Python at all, the chances are you’ve used iterators without even realising it. Writing your own and using them in your programs can provide significant performance improvements, particularly when handling large datasets or running in an environment with limited resources. They can also make your code more elegant and give you “Pythonic” bragging rights.

Here we’ll walk through the details and show you how to roll your own, illustrating along the way just why they’re useful.

Continue reading “Learn To Loop The Python Way: Iterators And Generators Explained”

ARM-Based NAS Is A Low Cost, Low Power Beauty

A NAS is always a handy addition to a home network, but they can be a little pricey. [Blake Burkhart] decided to create his own, prioritising budget and low power considerations, with a secondary objective to produce some router and IoT functionality on the side.

A Banana Pi R2 was a good choice to meet these requirements, being a router-based development board that also sports dual SATA connectors and gigabit Ethernet. [Blake] had some retrospective regrets about the performance of this particular SBC, but it does just fine when functioning purely as a NAS.

The enclosure for the device is a three bay hot-swap HDD module, with one of the bays gutted and used for the Banana Pi. It’s a simple idea, elegantly executed, which looks great. To access the ports of the Banana Pi, a custom acrylic side panel was laser cut, which also allowed LEDs to shine through – obligatory for any DIY server/computer build. When mounting this panel to the existing enclosure, [Blake] was reluctant to take his chances tapping the brittle acrylic, instead opting to melt the threads into the plastic with a pre-torched screw. We find that tapping acrylic is usually okay if you take it slow, but heat-tapping does sound fun.

The 12 V fan that came built into the hot-swap enclosure was too loud and awkwardly came in a non-standard size with a non-standard connector. What’s more, a buzzer alarm was triggered any time the fan was disconnected and 0 RPM was detected. [Blake]’s solution was to rewire the power pin of the connector to a 5 V rail; he found that running the fan at 5 V led to much quieter performance whilst keeping the HDDs sufficiently cool.

We find that when it comes to DIY network gear and routers, there are two approaches. Either create your own bespoke solution that perfectly fits your needs, like this perfect home router, or work around your current gear and build some tech to automatically reboot it for you.


No Signal For Your Radio-Controlled Watch? Just Make Your Own Transmitter

You can win any argument about the time when you have a radio controlled watch. Or, at least, you can if there’s any signal. [Henner Zeller] lives in a place where there is no reception of the DCF77 signal that his European wristwatch expects to receive. Consequently, he decided to make his own tiny transmitter, which emulates the DCF77 signal and allows the watch to synchronise.

A Raspberry Pi Zero W is the heart of the transmitter, and [Henner] manages to coax it into generating 77500.003Hz on a GPIO pin – close enough to the 77.5kHz carrier that DCF77 uses. The signal is AM, and transmits one bit/s, repeating every minute. A second GPIO performs the required attenuation, and a few loops of wire are sufficient for an antenna which only needs to work over a few inches. The Raspberry Pi syncs with NTP Stratum 1 servers, which gives the system time an accuracy of about ±50ms. The whole thing sits in a slick 3D printed case, which provides a stand for the watch to rest on at night; this means that every morning it’s synchronised and ready to go.

[Henner] also kindly took the time to implement the protocols for WWVB (US), MSF (UK) and JJY (Japan). This might be just as well, given that we recently wrote about the possibility of WWVB being switched off. Be sure to check the rules in your area before giving this a try.

We’ve seen WWVB emulators before, like this ATtiny45 build, but we love that this solution is an easy command line tool which supports many geographical locations.