Getting Error while running Rasa using Flask on AWS

Hi,

I am trying to host rasa as http service using flask. I am able to do it successfully on local windows environment.

But when I am deploying the same on AWS Elastic BeanStalk, I am running into Error - "" Exception set_wakeup_fd only works in main thread "" Which seems to be because of asyncio module of Python.

The strange thing about error is it only fails alternate REST API call from POSTMAN. When I am calling same REST API from another application it runs successfully in all consecutive hits.

Any help will be appreciated. I have tried few works around but could not solve error. Please let me know if you need more details around this.

Thanks!!!

Sharing the piece of code block which is throwing the error-

loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) data = loop.run_until_complete(agent.handle_text(message, sender_id=user_id))

Please do let me know if any other details needed.

Thanks!

Hi @Satvik sorry for getting back to you so late - are you still having this error? If yes, could you please post the full error trace and which commands you ran?

Hi @akelad, glad to hear from you!

Yes, I am still facing the error.

Here is full error stack-

DEBUG:2020-01-17 05:57:53,177:Start main & Handle text ERROR:2020-01-17 05:57:53,178:Exception set_wakeup_fd only works in main thread Traceback (most recent call last):

  • File “/opt/python/current/app/TrainedAgent.py”, line 55, in main*
  • data = loop.run_until_complete(self.agent.handle_text(message, sender_id=user_id))*
  • File “uvloop/loop.pyx”, line 1450, in uvloop.loop.Loop.run_until_complete*
  • File “uvloop/loop.pyx”, line 1443, in uvloop.loop.Loop.run_until_complete*
  • File “uvloop/loop.pyx”, line 1351, in uvloop.loop.Loop.run_forever*
  • File “uvloop/loop.pyx”, line 497, in uvloop.loop.Loop._run*
  • File “uvloop/loop.pyx”, line 281, in uvloop.loop.Loop._setup_or_resume_signals*
  • File “uvloop/loop.pyx”, line 270, in uvloop.loop.Loop._setup_or_resume_signals*
  • File “uvloop/loop.pyx”, line 3240, in uvloop.loop._set_signal_wakeup_fd* ValueError: set_wakeup_fd only works in main thread DEBUG:2020-01-17 05:57:53,178:Out of Main

Please do let me know if you need more details around it.

Hi @akelad,

I have been debugging error and have some varied scenarios to break/run.

My observations are-

  1. when RAM is less ( EBS/EC2 - t3.medium - 2 CPU, 4GB RAM ) - every alternate REST API request fails with the above mentioned error (set_wakeup_fd only works in main thread)

  2. when ( EBS/EC2 - r5.large - 2 CPU, 16GB RAM ) - i) no failure calling the REST API from another application ii) every alternate REST API request using POSTMAN fails with the above mentioned error (set_wakeup_fd only works in main thread)

Currently I am using r5.large instance but it also throws same error couple of occassions when there are multiple parallel (more than 5) request hits.

I am observing more and more use case scenarios. Please do let me know if you need any more information. Thanks a lot for your time and help.

Regards

@Satvik sorry for the delay in getting back to you - what kind of code are you using to host rasa as an http service? And is there any reason you’re not just using rasa run to run it as a server? that should work fine

Hi @akelad, apologies could not respond soon. I am using Flask REST for http/https layer on top of RASA codes. Hosting on AWS Elastic Beanstalk. Rationale, needed more control and features.

Could “rasa run” be used for product level features? If yes, Can share tutorial/guide for “rasa run”?

Also, can we try to debug the error and root cause highlighted by me in beginning.

Thanks a lot for your time and support.

Warm Regards

I’m not sure what you mean about using “rasa run” for product level features. What kind of extra functionality do you need?

I would need to see your code to determine what’s going wrong. I would guess it’s some async issue though