MagicMirror² v2.14.0 is available! For more information about this release, check out this topic.

Python Shell not working properly on MM

  • Hi guys,

    Im not too sure if anybody has this issue with the library var PythonShell = require('python-shell');.

    I wrote a python script that runs a RFID hardware that allows card tapping. Once someone taps the card, a music will play. The script works great on it’s on by using sudo python and it’s meant to be passive, meaning that the script will keep running once it’s activated. The music will only play once once it detects the first card and it will not replay it again. However, the problem comes in when I tried to run it via PythonShell on MagicMirror.

    I realized that the script got recalled multiple times while magicmirror is running. I realized this problem when i tap the card again. This results in me hearing echo music.

    Has anyone encountered this issue before?

  • Moderator

    @zichao92 The FRITZ-Box Callmonitor module uses PythonShell, e.g. here.

    What is the specific problem you are encountering? How do you start the script? It sounds like you simply need to make sure it is only started once, and then it should work? Can you show us the code responsible for it?

  • Hi again @Jopyth !
    I hope im not give you a technical nightmare. Here’s the code that i was running on my MM.

    const NodeHelper = require('node_helper');
    const Gpio = require('onoff').Gpio;
    const exec = require('child_process').exec;
    var csv = require('csv-parser');
    var fs = require('fs');
    var PythonShell = require('python-shell');
    var people; 
    module.exports = NodeHelper.create({
      start: function () {
        this.started = false;
        this.toggleOn = false;
    //exec("sudo python /home/pi/NicoRFID/"); // RFID, hk forced it here.
'../../../../../home/pi/NicoRFID/', function (err) {
      if (err) throw err;
    function chaofunction(){
      .on('data', function (data) {
        console.log('People Left: %s ', data.People_left);
        people = data.People_left;

    Notice'../../../../../home/pi/NicoRFID/', function (err) { if (err) throw err; console.log('finished'); });

  • Moderator

    @zichao92 Looks fine, not sure why it doesn’t work. You do not start he module multiple times, do you?

  • @Jopyth , im not too sure if i accidentally did it , is there any way to check it?

  • Moderator

    @zichao92 It usually should not start multiple helpers. You could insert a console.log("Script started!"); before the and see if it appears multiple times in the log?

  • @Jopyth , the console.log didnt even appear once although the RFID is working. Another issue is that the python script will suddenly stop functioning for no reason and it will start functioning again about 1 minute later ( i realized this when the RFID didnt have any response after i tapped a card. )

Log in to reply