How to open another tab in command line and proceed there with fabric?

123 views Asked by At

Basically, what I am trying to do is to start my django application.

Before I can do runserver, I need to start mongodb and redis by running mongod and redis-server respectively.

So, I though I could automate this instead of doing it every time.

My fabric function looks something like this:

def start_project():
    local("mongod") 
    local("redis-server")

But once it starts mongod the tab becomes busy and it will not execute redis-server.

Now, is it possible that I can do something like this?:

def start_meraki():
    local("mongod")
    open_another_tab()   # what can I do here?  
    local("redis-server") 

P.S. I am using Ubuntu 14.04

1

There are 1 answers

0
Alex Ivanov On BEST ANSWER

Not sure what you mean by "another tab" but I think you get stuck because python waits for the process to complete which is in the infinite loop. You need to detach the process from python after starting it. If I want Firefox to open another page in a separate tab I do like this:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import subprocess

def detach(cmd):
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

def start_everything():

    detach('firefox http://google.com')
    detach('firefox http://yahoo.com')

    # or you can start anything the same way

    detach('audacious')
    detach('leafpad')
    detach('gimp')

start_everything()