Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    boot.py Vs main.py

    Scheduled Pinned Locked Moved GPy
    3 Posts 2 Posters 69 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kjm
      last edited by

      I'm trying to figure out a way to determine if my gpy is running boot.py or main.py. None of the online suggestions for identifying the current process like

      import __main__
      print(__main__.__file__)
      
      AttributeError: 'module' object has no attribute '__file__'
      

      or

      import sys
      this_function_name = sys._getframe(  ).f_code.co_name
      
      AttributeError: 'module' object has no attribute '_getframe'
      

      or

      import sys
      print (sys.argv[0])
      
      IndexError: list index out of range
      

      work. Surely there must be a way in pycoms flavour of micropython to do this?

      1 Reply Last reply Reply Quote 0
      • C Offline
        crumble
        last edited by

        if you do normal stuff, both files shall run. First boot than main.

        You can set a local variable, a method or so, to print out for logging or to use in an if statement.

        Do you still hunt your syntax error bug? If yes, try to precompile your stuff. You may use too much memory too early, so that the on device compiler fails with strange messages. Frozen files will be better for testing. Even the *.mpy files need RAM and may fail when the memory is heavy fragmented on an early stage. But testing such issues with precompiled files is quite easy compared with the frozen workflow

        If you mix 4mb an lower device, develop on a smaller device and test the newer one quite often.

        1 Reply Last reply Reply Quote 0
        • K Offline
          kjm
          last edited by

          I've got identical copies of my non terminating software in boot.py & main.py, the idea being that if boot.py fails then main.py should run in lieu. But I'd like to get a diagnostic message when this happens so that's why I need a way of telling if the code is running as boot.py or main.py

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom