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

    _thread not working

    Scheduled Pinned Locked Moved Discussion
    1 Posts 1 Posters 346 Views 1 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 how to abandon a function call after 5s if the function hasn't returned a value by then.

      import _thread, time
      
      def _function(this, that):
        print('waiting for _function'); time.sleep(9); print("don't want to see this message")
      
      _thread.start_new_thread(_function, (1, 2))
      lock=_thread.allocate_lock()
      lock.acquire(1, 5)
      

      gives

      Running C:\Users\Kris\Google Drive\My Documents\Pycom\main\test.py
      
      >>>
      >>>
      waiting for _function
      >
      Pycom MicroPython 1.18.1.r7 [v1.8.6-849-d1c5ea9] on 2018-12-17; GPy with ESP32
      Type "help()" for more information.
      >>>
      >>> don't want to see this message
      
      

      isn't forcing the function to exit after 5s. Can someone show me how to achieve this?

      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