Hi,
So long time , alot of coding . i figure out some issues..
I have a "old way" script.. that prosess alot of data and I can see that I having problems with the multiprosess requests..
My script uses aprox 2-3 seconds to complete.
the script is simple
main script - receive a event trap, decode the payload and call other event
next event - splitt payload and post into mysql and call "many" events....
many scripts - check splitts and "do something"
end - write into db.
Is there any quick way to let eventghost or python "que" the prosess?
Greetings Eddie
Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
Multiprossecing
Re: Multiprossecing
i am using "trigger event" to activate my sub rutines.
But "trigger event" does not have any "wait for executed \ finish ...
is there any simple ways to "que" my tasks?
Or maybe call sub scripts/events with "wait for finish" ??
But "trigger event" does not have any "wait for executed \ finish ...
is there any simple ways to "que" my tasks?
Or maybe call sub scripts/events with "wait for finish" ??
-
krambriw
- Plugin Developer
- Posts: 2570
- Joined: Sat Jun 30, 2007 2:51 pm
- Location: Stockholm, Sweden
- Contact:
Re: Multiprossecing
Yes, to avoid that EG is pausing the rest while your scripts are executing you have to run them in so called threads. This means that they will be processed in parallel to EG itself (simplified explanation).
To achieve that, you need to break down your script functionality into callable functions.
Suppose your script would have functions defined something like this (obviously you will have to add the proper code of what to do in each function):
To call those functions you can do it in several ways, either you can
- use EG's built in scheduler
- or you can use Timer from threading
- or you could start a thread.
I show you here how you can use the EG's built in scheduler. So the script template could look like this:
To achieve that, you need to break down your script functionality into callable functions.
Suppose your script would have functions defined something like this (obviously you will have to add the proper code of what to do in each function):
Code: Select all
def mainScript():
#receive a event trap, decode the payload and call other event
def nextEvent():
#split payload and post into mysql and call "many" events....
def manyScripts()
#check splitts and "do something"
def theEnd():
#write into db.
To call those functions you can do it in several ways, either you can
- use EG's built in scheduler
- or you can use Timer from threading
- or you could start a thread.
I show you here how you can use the EG's built in scheduler. So the script template could look like this:
Code: Select all
import time
def mainScript(payload):
def nextEvent(payload):
print "split payload and post into mysql and call 'many' events...."
res = payload.split('.')
print res[1]
time.sleep(5)
manyScripts(res[1])
def manyScripts(event):
print "check splitts and 'do something'"
time.sleep(2)
theEnd(event)
def theEnd(event):
print "write into db."
print event
print "receive a event trap, decode the payload and call other event"
nextEvent(payload)
payload = "my.event"
eg.scheduler.AddTask(0.1, mainScript, payload)
My released plugins
https://drive.google.com/drive/folders/ ... y01eVBKeHM
https://drive.google.com/drive/folders/ ... y01eVBKeHM
Re: Multiprossecing
tnx Krambriw...
i using:
eg.plugins.EventGhost.TriggerEvent(u'scrip1', 0.0)
so i guess i can use:
def manyScripts(event):
print "check splitts and 'do something'"
eg.plugins.EventGhost.TriggerEvent(u'scrip1', 0.0)
time.sleep(2)
theEnd(event)
1. is there any other ways/syntax to call other scripts/events inside eventghost?
2. will time.sleep(2) be the key to "que"
3. I have not tryed "nextevent"
Eddie
i using:
eg.plugins.EventGhost.TriggerEvent(u'scrip1', 0.0)
so i guess i can use:
def manyScripts(event):
print "check splitts and 'do something'"
eg.plugins.EventGhost.TriggerEvent(u'scrip1', 0.0)
time.sleep(2)
theEnd(event)
1. is there any other ways/syntax to call other scripts/events inside eventghost?
2. will time.sleep(2) be the key to "que"
3. I have not tryed "nextevent"
Eddie
-
krambriw
- Plugin Developer
- Posts: 2570
- Joined: Sat Jun 30, 2007 2:51 pm
- Location: Stockholm, Sweden
- Contact:
Re: Multiprossecing
I do not follow what you wanna do. Your first question was "how to queue" tasks. The answer is you do it by scheduling them (that is what I made an example of)
I think you have to publish your script/scripts to allow us to help or describe in detail what you try to do, otherwise it will be impossible to understand
time.sleep(2)
Do you really understand Python????
I think you have to publish your script/scripts to allow us to help or describe in detail what you try to do, otherwise it will be impossible to understand
time.sleep(2)
Do you really understand Python????
My released plugins
https://drive.google.com/drive/folders/ ... y01eVBKeHM
https://drive.google.com/drive/folders/ ... y01eVBKeHM
Re: Multiprossecing
Yes, I am total newbee ...
I know what I want, know the ide and how the prosess should work, but i do not know Python good programming..
I attach the layout of my scripts.... And I will test your good tips for Schedule.task it
the primary scrips look like this...
My question is...
if I use your nice example...
will it QUE the prosess from start to end (after all subrutines has been executed) or do I have to add "eg.scheduler.AddTask(0.1, mainScript, payload)" in all subscripts???
tnx...
Eddie
I know what I want, know the ide and how the prosess should work, but i do not know Python good programming..
I attach the layout of my scripts.... And I will test your good tips for Schedule.task it
the primary scrips look like this...
Code: Select all
import sys
import time
import datetime
sys.setdefaultencoding('UTF8')
WL = eg.event.payload
eg.globals.workload = WL
#
Sender = WL[0].split('=')[1];
eg.globals.xSender = Sender
print WL
# 1 = DOWN, 0 = UP
DOWN = '0'
ts = time.time()
eg.globals.ReceiveTime = datetime.datetime.fromtimestamp(ts).strftime('%d%m%Y-%H%M%S')
if DOWN == '1':
eg.globals.xSmsmessage = "EasyPieceEye is down for upgrade, please check back later"
print eg.globals.xSmsmessage
if eg.globals.xSender == '+4793096222' or eg.globals.xSender == '93096222':
eg.plugins.EventGhost.TriggerEvent(u'EPE-Incomming', 0.0)
else:
#Calling SENDSMS
eg.plugins.EventGhost.TriggerEvent(u'EPE-SendSMS', 0.0)
else:
eg.plugins.EventGhost.TriggerEvent(u'EPE-Incomming', 0.0)
My question is...
if I use your nice example...
will it QUE the prosess from start to end (after all subrutines has been executed) or do I have to add "eg.scheduler.AddTask(0.1, mainScript, payload)" in all subscripts???
tnx...
Eddie
-
krambriw
- Plugin Developer
- Posts: 2570
- Joined: Sat Jun 30, 2007 2:51 pm
- Location: Stockholm, Sweden
- Contact:
Re: Multiprossecing
It depends...will it QUE the prosess from start to end (after all subrutines has been executed) or do I have to add "eg.scheduler.AddTask(0.1, mainScript, payload)" in all subscripts???
If you wanna give control back to EG somewhere in the script, you just schedule that first part and then when EG has finished whatever, you schedule the next part and so on until the end
If everything can be done in one script, you can schedule everything in one schedule
My released plugins
https://drive.google.com/drive/folders/ ... y01eVBKeHM
https://drive.google.com/drive/folders/ ... y01eVBKeHM
-
m19brandon
- Experienced User
- Posts: 177
- Joined: Mon Feb 03, 2014 10:36 pm
Re: Multiprossecing
Thanks for the sample @krambriw