You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Define two subscriber listening for the event above. Each subscriber has a listener method with the name on_event
Each of the subscriber classes above defines an instance field, but with unique name (self.something in the first class, self.something2 in the second class)
Define another class that posts an event
Run this scenario and get the error below:
Exception in thread thread-on_event:
Traceback (most recent call last):
File "C:\Anaconda2\envs\python\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:\Anaconda2\envs\python\lib\site-packages\pyeventbus\pyeventbus.py", line 112, in run
self.method(self.subscriber, self.event)
File "C:/FractureID/projects/python/ui/spectraqc/PyEventBusBug.py", line 16, in on_event
print (self.something)
AttributeError: Subscriber2 instance has no attribute 'something'
Exception in thread thread-on_event:
Traceback (most recent call last):
File "C:\Anaconda2\envs\python\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:\Anaconda2\envs\python\lib\site-packages\pyeventbus\pyeventbus.py", line 112, in run
self.method(self.subscriber, self.event)
File "C:/FractureID/projects/python/ui/spectraqc/PyEventBusBug.py", line 26, in on_event
print (self.something_else)
AttributeError: Subscriber1 instance has no attribute 'something_else'
It complains about the variable in class two not having the attribute in the first class and the other way around.
If I change on of the on_event to something else like on_event2 then the issue is gone.
from pyeventbus import *
class SomeEvent:
def __init__(self):
pass
class Subscriber1:
def __init__(self):
self.something = 'First subscriber'
PyBus.Instance().register(self, self.__class__.__name__)
@subscribe(threadMode=Mode.PARALLEL, onEvent=SomeEvent)
def on_event(self, event):
print (self.something)
class Subscriber2:
def __init__(self):
self.something_else = 'Second subscriber'
PyBus.Instance().register(self, self.__class__.__name__)
@subscribe(threadMode=Mode.PARALLEL, onEvent=SomeEvent)
def on_event(self, event):
print (self.something_else)
class PyEventBusBug:
def __init__(self):
Subscriber1()
Subscriber2()
PyBus.Instance().post(SomeEvent())
if __name__ == "__main__":
PyEventBusBug()
The text was updated successfully, but these errors were encountered:
Please see the code below. To summarize:
Run this scenario and get the error below:
It complains about the variable in class two not having the attribute in the first class and the other way around.
If I change on of the on_event to something else like on_event2 then the issue is gone.
The text was updated successfully, but these errors were encountered: