Jump to content


Photo

hide spinner during plugin execution


  • Please log in to reply
50 replies to this topic

Re: hide spinner during plugin execution #41 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 30 August 2017 - 11:42

So ,

Here is what Ive coded up, works perfectly. Emulates a very simple - albeit hack - message driven model.

 

from Queue import Queue
from threading import Thread
from enum import Enum


# State of this worker thread
class State(Enum):
    Stopped = 0x01
    Idle    = 0x02
    Busy    = 0x04


# Threding Queue. All messages for work are posted into this.
Queue = Queue(maxsize=0)


# Message blocks placed on queue
class MessageBlock(object):
    def __init__(self, type, callback):
        self._type = type
        self._callback = callback
    
    def doAction(self):
        self._callback()


class Worker:
    _state = State.Stopped 


    def state(self):
        return self._state 


    def setBusy(self):
        print("setBusy()")
        self._state = State.Busy


    def setIdle(self):
        print("setIdle()")
        self._state = State.Idle


    def stop(self):
        print("Stop()")
        self._state = State.Stopped


    def start(self):
        print("Start()")
        self.setIdle()
        print("start: setting up worker")
        worker = Thread(target=self.doMainLoop, args=(Queue,))
        worker.setDaemon(True)
        worker.start()
        print("start: join queue")
        Queue.join()
        #print("start: stopping")
        #self.stop()


    def doMainLoop(self, messageQueue):
        print("doMainLoop() state={}".format(self.state()))
        print
        while self.state() != State.Stopped:
            print("doMainLoop: starting loop")
            self.setIdle()
            message = messageQueue.get()
            self.setBusy()
            print("doMainLoop: invoking doAction of message block")
            message.doAction()
            messageQueue.task_done()
            print("doMainLoop: action done")
        print("doMainLoop() ends")
            


def callbackFunc():
    print ("callback function called")
you then import Worker and can instantiate the class:
   
msg = Worker.MessageBlock("proc",Worker.callbackFunc)
worker = Worker.Worker()
worker.start()
...
<setup msg>
Worker.Queue.put(msg)
...
<setup msg>
Worker.Queue.put(msg)
..
worker.stop()

Simple and effective. Probably need coding ettiqute and style, and not what members would end up with, but works for me. 

 

All I need to do throug my code is setup a series of simple message blocks consisting of a name and a callback functions, and push these into the Queue; the callback functions can (I guess - not tried yet!!) setup their own message blocks to prevent blocking. The worker thread will non-block wait for messages to be pushed into the queue and invoke the callback specified within the message. I will of course need to add message data and arguments, a trivial matter, but I wanted to share this with the community given the pain I had to endure to get here. I always like to help ;)

 

 

Tags to help future searches:

blocking

messaging

threading

multitasking

spinner

worker 



Re: hide spinner during plugin execution #42 MiLo

  • PLi® Core member
  • 14,055 posts

+298
Excellent

Posted 30 August 2017 - 16:59

Uh, you are aware that Enigma2 is already running a message based framework (called "twisted") that already has a messaging system for you to use? I think I mentioned  both threading and twisted before...


Real musicians never die - they just decompose

Re: hide spinner during plugin execution #43 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 31 August 2017 - 07:15

Uh, you are aware that Enigma2 is already running a message based framework (called "twisted") that already has a messaging system for you to use? I think I mentioned  both threading and twisted before...

Yes, only by virtue of your reference to it, by name.

 

No specific examples - simple stuff , like just a few lines as provided by @hyperonex - were provided by anyone despite me asking several times, pleading. I found the whole experience very unhelpful and almost like members who had achieved something wanted me to "suffer" as they did , rather than share their solutions. Not good behaviours so far as I am concerned. And I fully expected that, in the absence of specific coded examples, when I wrote my own, someone would come back and take it to pieces !!!!!!!!!!! 

 

So no, I didnt know , there is no documentation , and no one is going to provide snippets of code are they !


Edited by keratos, 31 August 2017 - 07:16.


Re: hide spinner during plugin execution #44 Erik Slagter

  • PLi® Core member
  • 46,969 posts

+542
Excellent

Posted 1 September 2017 - 09:36

P.S. It's still a hobby. I don't earn money with it ...

That's one (quite relevant) aspect, another being that users really don't want us to spend our limited time on documentation, they want features!


* Wavefrontier T90 with 28E/23E/19E/13E via SCR switches 2 x 2 x 6 user bands
I don't read PM -> if you have something to ask or to report, do it in the forum so others can benefit. I don't take freelance jobs.
Ik lees geen PM -> als je iets te vragen of te melden hebt, doe het op het forum, zodat anderen er ook wat aan hebben.


Re: hide spinner during plugin execution #45 MiLo

  • PLi® Core member
  • 14,055 posts

+298
Excellent

Posted 1 September 2017 - 17:04

"Good behaviour" in any open source project means that the very first thing you do is publish your contribution or first code. You'll get more by giving more. You'll get lots and lots of feedback and advise that way, and they'll be very specific, relating to your code. Just posting some general questions like "how do I stop the spinners from appearing" will only get you generic answers like "Delegate to a thread or use non-blocking IO".

 

If you want documentation, the proper way to ask would be "Hey here's some documentation I wrote, could this be made part of the source?"


Edited by MiLo, 1 September 2017 - 17:06.

Real musicians never die - they just decompose

Re: hide spinner during plugin execution #46 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 21 September 2017 - 14:55

"Good behaviour" in any open source project means that the very first thing you do is publish your contribution or first code. You'll get more by giving more. You'll get lots and lots of feedback and advise that way, and they'll be very specific, relating to your code. Just posting some general questions like "how do I stop the spinners from appearing" will only get you generic answers like "Delegate to a thread or use non-blocking IO".

 

If you want documentation, the proper way to ask would be "Hey here's some documentation I wrote, could this be made part of the source?"

 

For fucks sake. What a pretentious twat you really are. I am never ceased to be surprised by the arrogance and inflated egos of individuals such as you.

 

"A right way and a wrong way"

 

What a prick



Re: hide spinner during plugin execution #47 Erik Slagter

  • PLi® Core member
  • 46,969 posts

+542
Excellent

Posted 21 September 2017 - 15:14

MiLo has every right to be pretentious as he has contributed quite a bit more to this project than you.

 

And by the way, cursing does not count as contribution.


* Wavefrontier T90 with 28E/23E/19E/13E via SCR switches 2 x 2 x 6 user bands
I don't read PM -> if you have something to ask or to report, do it in the forum so others can benefit. I don't take freelance jobs.
Ik lees geen PM -> als je iets te vragen of te melden hebt, doe het op het forum, zodat anderen er ook wat aan hebben.


Re: hide spinner during plugin execution #48 WanWizard

  • PLi® Core member
  • 70,542 posts

+1,812
Excellent

Posted 21 September 2017 - 15:20

I would like to go one step further.

 

With this attitude, and using this kind of language, you are free to move on. If you want something, either pay for it, or wait patiently until it is given for you for free, if at all. There aren't any more options. If you don't like that, again, you are free to move on.

 

In the meantime, contemplate on the language you have used, and look up what open source is, what you can expect from it, and what your rights are. And come back when you understand it, and want to live by it.


Currently in use: VU+ Duo 4K (2xFBC S2), VU+ Solo 4K (1xFBC S2), uClan Usytm 4K Ultimate (S2+T2), Octagon SF8008 (S2+T2), Zgemma H9.2H (S2+T2)

Due to my bad health, I will not be very active at times and may be slow to respond. I will not read the forum or PM on a regular basis.

Many answers to your question can be found in our new and improved wiki.


Re: hide spinner during plugin execution #49 MiLo

  • PLi® Core member
  • 14,055 posts

+298
Excellent

Posted 21 September 2017 - 17:05

I always have to pay extra for airline tickets because my ego weighs more than 32kg and won't fit in the luggage compartment.

The only valid currency in open source is "code lines". Trying to pay cash for open source development is like attempting to convince a donkey to pull your cart for dollars. It won't work, the bills have no value. Either give it a carrot or find someone who'll trade carrots for money.
Real musicians never die - they just decompose

Re: hide spinner during plugin execution #50 Erik Slagter

  • PLi® Core member
  • 46,969 posts

+542
Excellent

Posted 21 September 2017 - 17:42

Apparently cursings don't work very well as a trade for carrots :D


* Wavefrontier T90 with 28E/23E/19E/13E via SCR switches 2 x 2 x 6 user bands
I don't read PM -> if you have something to ask or to report, do it in the forum so others can benefit. I don't take freelance jobs.
Ik lees geen PM -> als je iets te vragen of te melden hebt, doe het op het forum, zodat anderen er ook wat aan hebben.


Re: hide spinner during plugin execution #51 MiLo

  • PLi® Core member
  • 14,055 posts

+298
Excellent

Posted 22 September 2017 - 18:39

I've seen people get reasonable results with cursing though. On donkeys that probably better than money.
Real musicians never die - they just decompose


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users