project-receptor / receptor-stresstest

A Receptor plugin to stress-test the mesh
0 stars 1 forks source link

module 'asyncio' has no attribute 'run' #1

Open jhutar opened 4 years ago

jhutar commented 4 years ago

I have installed stresstest into RHEL7 receptor deployment:

pip3 install git+https://github.com/project-receptor/receptor-stresstest

where I have:

[root@localhost receptor]# rpm -qa | grep -e python -e receptor | sort
dbus-python-1.1.1-9.el7.x86_64
libxml2-python-2.9.1-6.el7_2.3.x86_64
python-2.7.5-86.el7.x86_64
python-backports-1.0-8.el7.x86_64
python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch
python-chardet-2.2.1-3.el7.noarch
python-dateutil-1.5-7.el7.noarch
python-decorator-3.4.0-3.el7.noarch
python-dmidecode-3.12.2-3.el7.x86_64
python-ethtool-0.8-8.el7.x86_64
python-gobject-base-3.22.0-1.el7_4.1.x86_64
python-iniparse-0.4-9.el7.noarch
python-inotify-0.9.4-4.el7.noarch
python-ipaddress-1.0.16-2.el7.noarch
python-kitchen-1.1.1-5.el7.noarch
python-libs-2.7.5-86.el7.x86_64
python-pycurl-7.19.0-19.el7.x86_64
python-setuptools-0.9.8-7.el7.noarch
python-six-1.9.0-2.el7.noarch
python-syspurpose-1.24.13-4.el7_7.x86_64
python-urlgrabber-3.10-9.el7.noarch
python3-3.6.8-10.el7.x86_64
python3-aiohttp-3.6.2-4.el7ar.x86_64
python3-async-timeout-3.0.1-2.el7ar.noarch
python3-attrs-19.3.0-3.el7ar.noarch
python3-chardet-3.0.4-10.el7ar.noarch
python3-dateutil-2.8.1-2.el7ar.noarch
python3-idna-2.4-2.el7ar.noarch
python3-idna-ssl-1.1.0-2.el7ar.noarch
python3-libs-3.6.8-10.el7.x86_64
python3-multidict-4.7.4-2.el7ar.x86_64
python3-pip-9.0.3-5.el7.noarch
python3-prometheus-client-0.7.1-2.el7ar.noarch
python3-receptor-satellite-1.0.1-1.el7sat.noarch
python3-setuptools-39.2.0-10.el7.noarch
python3-six-1.11.0-8.el7ar.noarch
python3-typing-extensions-3.7.4.1-2.el7ar.noarch
python3-yarl-1.4.2-2.el7ar.x86_64
receptor-0.6.1-1.el7ar.noarch
rpm-python-4.11.3-40.el7.x86_64

and when I attempted to trigger the test from the controller, it says:

ERROR 2020-03-30 19:34:57,096 8cec1094-12b6-457b-aec4-35116084edf4 work Error encountered while handling the response, replying with an error message (module 'asyncio' has no attribute 'run')
ERROR 2020-03-30 19:34:57,105 8cec1094-12b6-457b-aec4-35116084edf4 work ['  File "/usr/lib/python3.6/site-packages/receptor/work.py", line 100, in handle\n    work_exec.result()\n', '  File "/usr/lib64/python3.6/concurrent/futures/_base.py", line 425, in result\n    return self.__get_result()\n', '  File "/usr/lib64/python3.6/concurrent/futures/_base.py", line 384, in __get_result\n    raise self._exception\n', '  File "/usr/lib64/python3.6/concurrent/futures/thread.py", line 56, in run\n    result = self.fn(*self.args, **self.kwargs)\n', '  File "/usr/local/lib/python3.6/site-packages/receptor_stresstest/worker.py", line 48, in blunderbuss\n    asyncio.run(response_generator.run())\n']
jhutar commented 4 years ago

Hello. I have no idea on what am I doing, but it seems to work like this:

--- /usr/local/lib/python3.6/site-packages/receptor_stresstest/worker.py    2020-03-30 21:11:20.000000000 +0000
+++ /usr/local/lib/python3.6/site-packages/receptor_stresstest/worker.py.CHANGED    2020-03-30 21:11:04.092821896 +0000
@@ -23,10 +23,11 @@
         self.size = size

     async def run(self):
+        loop = asyncio.get_event_loop()
         seconds_left = self.length
         while seconds_left:
             for _ in range(self.rate):
-                asyncio.create_task(self.emit())
+                loop.create_task(self.emit())
             await asyncio.sleep(1)
             seconds_left -= 1
         await asyncio.sleep(1)
@@ -45,7 +46,10 @@
 def blunderbuss(message, config, queue):
     args = json.loads(message.raw_payload)
     response_generator = Blunderbuss(queue, **args)
-    asyncio.run(response_generator.run())
+    loop = asyncio.new_event_loop()
+    asyncio.set_event_loop(loop)
+    loop.run_until_complete(response_generator.run())

 blunderbuss.receptor_export = True
matburt commented 4 years ago

@jhutar can you post a PR to make that change? This is happening because stresstest is written towards python 3.8 but the rest of receptor requires python 3.6

jhutar commented 4 years ago

Hello @matburt. Well, I have absolutely no idea how asyncio works. I just put 2 StackOverflow answers together to make this work, so I would prefer if somebody competent would do the change. But if the change seems good and there is no more work needed on it, I will happily create the PR.

matburt commented 4 years ago

Doesn't matter! It looks good to me so open a PR!