OK we are going to go to school
AddTask(self, waitTime, func, *args, **kwargs):
this is the method for eg.scheduler.AddTask
the self you are going to ignore. but the waitTime, func, *args, **kwargs we are not
waitTime is pretty obvious
func is the function you want to run
and *args is the information you want to pass to func but these are positional arguments
and **kwargs is the information you want to pass to func these are keyword arguments
so what is happening is you are actually calling urllib.urlopen and not letting the scheduler do it because you have surrounded your information in ()'s without having a , between urllib.urlopen and the ()'s.
now because you don't want to pass a tuple as a positional argument containing your information you just want to pass the information it's self you will ditch the ()'s and put a , between urllib.urlopen and your information
so as an example
Code: Select all
eg.scheduler.AddTask(0.1, eg.TriggerEvent, 'Some_Suffix', None, 'Some_Prefix')
Code: Select all
eg.scheduler.AddTask(0.1, eg.TriggerEvent, prefix='Some_Prefix', suffix='Some_Suffix')
the 2 above examples do exactly the same thing. but one uses positional arguments and the other uses keyword arguments. the purpose to keyword arguments is if the person that wrote the code has set default values for some of the arguments.
as with Triggerevent it is coded like so.
the use of source is nothing you would have to worry about so i omitted it from this example
Code: Select all
TriggerEvent(self, suffix='', payload=None, prefix='Main')
so we can see that suffix is defaulted to blank. then payload is None and prefix is Main. so if we only wanted to supply a prefix.
instead of doing this
Code: Select all
TriggerEvent('', None, 'Some_Prefix')
we can do this, which is easier to understand. the code will leave the default values in place and only change the default value for prefix to 'Some_Prefix'
Code: Select all
TriggerEvent(prefix='Some_Prefix')
so with the scheduler a mechanism was provided so you can specify a specific argument or you can positionally set them. But you do not want to run the function as you are passing it to the scheduler. you want the scheduler to run it for you.. you error is because there is a returned value from running either one of those functions. in the case of urllib it returns a addinfourl object. so what you are really passing to the scheduler is the addinfourl object and then an argument of "MyEvent2" to be passed to that object so what is actually happening is this
now this is not what you want to have happen..
Code: Select all
addinfourl = urllib.urlopen("http://127.0.0.1:8080/json.htm?blabla")
addinfourl("MyEvent2")
Code: Select all
event = eg.TriggerEvent("Action", payload="bla", prefix="Prefix", source=eg)
event("MyEvent1")
you want the scheduler to run urllib,urlopen or eg.TriggerEvent
"MyEvent2" has no use
Code: Select all
eg.scheduler.AddTask(0.1, urllib.urlopen, "http://127.0.0.1:8080/json.htm?blabla")
Code: Select all
eg.scheduler.AddTask(0.1, eg.TriggerEvent, prefix="MyEvent1", suffix="Action", payload="bla")
or
Code: Select all
eg.scheduler.AddTask(0.1, eg.TriggerEvent, "Action", "bla", "MyEvent1")
Now here comes a little spin on it. position arguments and keywords arguments can be passed at the same time. so long as the positional arguments are passed first and then the keyword arguments. and anything without a default value HAS to be filled in before any keyword arguments are passed.
so this will make the suffix as "Action" and the prefix as "MyEvent1" and it will leave the payload at it's default of None
Code: Select all
eg.scheduler.AddTask(0.1, eg.TriggerEvent, "Action", prefix="MyEvent1")
Now when your head is done throbbing.. and you have taken a grip of migraine pills. come on back and ask away. this is a whole lot of information to grasp. and I tried to do my best to explain it fully and tried to do it in a way that is easiest to understand. don't kill yourself about trying to guess it it. if something is unclear (which i fully understand, took me a hell of a long to to get a handle on this bit of python) tell me what piece you are having an issue with. and how you think it should be working with the explanation i gave. a lot of times this will help me think of a better way to go about explaining something. (gives me a clue as to how your brain translates the information so i can alter it to fit how your bean works)