简体   繁体   English

可以在Django中使用ROS吗?

[英]Is it possible to use ROS in Django?

I'm currently working on a webapp built on the Django framework. 我目前正在开发基于Django框架的webapp。 One of the functionalities it needs is to be able to communicate with ROS. 它需要的功能之一是能够与ROS通信。 However, ROS function need to be run on the main thread and from what I understand django spawns new threads each time. 但是,ROS功能需要在主线程上运行,据我了解,django每次都会生成新线程。 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. 因此,当我尝试调用ROS函数时,我收到错误消息,说它不起作用,因为它不在主线程上。 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. 我尝试编写一个单独的python脚本并将其导入视图并从那里调用它,但是我仍然遇到相同的错误。 Does anyone know of a workaround to this problem in Django? 有人知道在Django中解决此问题的方法吗?

You should be able to specify the number of threads/workers in config of your app server (wsgi or gunicorn, etc.). 您应该能够在应用服务器的配置(wsgi或gunicorn等)中指定线程/工作人员的数量。 For example, when using gunicorn, you can specify one thread . 例如,当使用gunicorn时,您可以指定一个线程

Alternatively, you can put all of your ROS calls into something like celery and then queue up tasks to it from your django views. 或者,您可以将所有ROS调用放入诸如celery之类的东西,然后从Django视图中将任务排队。 Much like gunicorn, you can run celery in single-process mode which makes it act as if it were single-threaded. 就像gunicorn一样,您可以在单进程模式下运行celery,这使其像单线程一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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