Skip to content

error running endless python script #81

Description

@moshebeeri

for example:

while True:
        value += 1
        print(value)
        time.sleep(seconds)

Activity

  1. anhquoctran commented on May 9, 2017

    @anhquoctran

    Me too, nothing happened when executing a script, onMessage not working

  2. moshebeeri commented on May 9, 2017

    @moshebeeri
    Author

    That's worked for me

    def emit_values():
        point = {
          # what ever you emit
        }
        print(json.dumps(point))
        sys.stdout.flush()           #<------SUPPER IMPORTANT!!!
        threading.Timer(interval, emit_values).start()
    
    if __name__ == '__main__':
        ap = argparse.ArgumentParser()
        ap.add_argument("-i", "--interval", type=int, default=60, help="sample interval")
    
        threading.Timer(args.interval, emit_values).start()
    

    Hope it helps

  3. anhquoctran commented on May 9, 2017

    @anhquoctran

    OK, good, that also worked for me, thank you bro

  4. zoellner commented on May 9, 2017

    @zoellner

    alternatively/in addition you can also set pythonOptions to include -u when creating a new python shell

    const pyshell = new PythonShell('script.py', {
      pythonOptions: '-u' //disable python output buffering
    });
    
  5. Almenon commented on Feb 14, 2018

    @Almenon
    Collaborator

    Thanks @zoellner and @moshebeeri . Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions