Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9099945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:44:43+00:00 2026-06-17T00:44:43+00:00

Is there a way to know which application I’m running a python script from?

  • 0

Is there a way to know which application I’m running a python script from?

I can run python from multiple sources, like Textmate, Sublime Text 2 or Terminal (I’m on Mac OSX). How can I know, exactly which tool launched the current python app.

I’ve tried looking into the os and inspect modules, but couldn’t find the solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:44:45+00:00Added an answer on June 17, 2026 at 12:44 am

    You can use psutil to do this sort of thing in a fairly cross-platform way:

    import psutil
    import os
    my_process = psutil.Process(os.getpid())
    parent = my_process.parent
    print "Parent process name: " + parent.name
    

    From the psutil documentation:

    It currently supports Linux, Windows, OSX and FreeBSD, both 32-bit and 64-bit, with Python versions from 2.4 to 3.3 by using a single code base.

    As well as the name you can get the executable path (which might be more useful if you’re selecting from a list of options) and also the full command-line with which it was invoked. You can also get the username who ran the process. See the psutil classes documentation for details of the parameters and the platforms on which they’re available.

    As an aside, if at all possible I would structure your code so that you don’t have to modify your behaviour according to the calling application – it would be much preferable to have the calling application pass in a parameter which modifies the behaviour of the shared code. However, I appreciate that sometimes other concerns take precedence over cleanliness of code, so psutil should enable you to do what you requested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know if there is any way by which I can paste
Is there a way to know when code is being called from running a
Is there any way to know which version of MS-Office I have on my
I want to know is there any way or message in MFC by which
I there a way to know which item has the focus in and WPF
I making a social application which requires Google+. I know that I can open
We have an Adobe AIR application which could be possibly downloaded from multiple domains.
Is there any way to know in Servlet is JS is enable or not
Is there a way to know where is set a given PHP config property?
Is there a way to know if Visual C++ 2008 SP1 Redistributable Package is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.