简体   繁体   中英

Is it possible to use ROS in Django?

I'm currently working on a webapp built on the Django framework. One of the functionalities it needs is to be able to communicate with ROS. However, ROS function need to be run on the main thread and from what I understand django spawns new threads each time. Due to this when I attempt to call ROS functions, I get errors saying that it won't work because it's not on the main thread. I've tried writing a separate python script and importing it into the views and calling it from there, but I still get the same errors. Does anyone know of a workaround to this problem in Django?

You should be able to specify the number of threads/workers in config of your app server (wsgi or gunicorn, etc.). For example, when using gunicorn, you can specify one thread .

Alternatively, you can put all of your ROS calls into something like celery and then queue up tasks to it from your django views. Much like gunicorn, you can run celery in single-process mode which makes it act as if it were single-threaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM