Forums

ConnectionRefusedError - attempt at multiprocessing

Hello, im trying to do some multiprocessing where my django app fetches data from another process, like it would from a database.

On my machine this is working fine, im using the Listener and Client classes from multiprocessing module and i believe they connect via sockets since i suply 'localhost' and port. When trying to do this on pythonanywhere i get a ConnectionRefusedError. it seems to me that the programs i run on the console aren't visible to my django app? I'm able to do this process comunication fine, if i run 2 programs from the console, however, my django webapp can't. Is this even possible to do? is my django app running on another machine? if yes, can i connect to the machine that runs my console?

Is your Django app running in a virtual environment? If so your console code may also need to be running in the virtual environment. The easiest way to do this would be on the "web app" tab scroll down to where you specify the virtual environment and click the "Start a console in this virtualenv" link

In response to this:

is my django app running on another machine?

Yes, that's right. Your website will be running on one machine, and anything you start in a console will be on a different one. Different consoles are also normally on different machines (though on occasion they might be on the same one), and scheduled tasks and always-on tasks also run on separate hardware.

For Django, the best way to communicate between processes like that would be to use the database -- that is, the MySQL or SQLite one (we recommend MySQL) that you specify in your settings.py. Code that isn't running as part of the website itself can be written as custom management commands, so that it gets access to all of your Django models and so on.