Jump to content


keratos

Member Since 27 Nov 2014
Offline Last Active 20 Apr 2018 13:12
-----

Posts I've Made

In Topic: hide spinner during plugin execution

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


In Topic: hide spinner during plugin execution

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 !


In Topic: hide spinner during plugin execution

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 


In Topic: hide spinner during plugin execution

30 August 2017 - 07:14

I hope it works for you. Just make sure to handle the concurrent access to your progress bar if any

Yes, I do have a PB and will codify so that the threads report progress to a progress thread ... 

 

until someone - or indeed myself - identifies a better way than threads


In Topic: hide spinner during plugin execution

29 August 2017 - 18:50


What I've done to send an HTTP request to a server without blocking the main loop while waiting for the request is the following

threading.Thread(target=functionNameToSendData,args=(inputs,)).start()

THANK YOU
THANK YOU
THANK YOU

i shall recode to use this model