简体   繁体   中英

Heroku Python deployment with two .py files using only one dyno

What is the easiest way to deploy a python app with only two .py files but keep it in one dyno? My files are friend.py and foe.py and my Procfile looks like this:

worker: python friend.py
worker: python foe.py

But when deployed to Heroku, the only dyno I have is foe.py. I've read other similar questions but they seem to complicated and I don't yet understand the inner workings of a python web application.

If they are distinct processes working in parallel, the most direct path is two dynos, using different names (actually, friend and foe would work fine as process names) in the Procfile . Right now, you are using the name worker twice, so foe.py shows up because it's the last one defined. Two things to keep in mind -

  • The names in Procfile can be arbitrary; as far as I know, the only "special" name is web , which tells Heroku to expect that process to bind to a port and accept HTTP traffic from the routing mesh. worker isn't special; it's just a convention people tend to use for "something running other than the web dyno"
  • A dyno is closer to a Docker container than a virtual machine, so the general best practice is one kind of process per container.

If you really need only one dyno (cost?), you could write a third script whose sole job is to spawn friend.py and foe.py as subprocesses. In that case, everything comes up and down as a unit; you can't manage friend and foe independently.

Hope that helps.

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