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

  • Home
  • SEARCH
  • 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 616227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:18:15+00:00 2026-05-13T18:18:15+00:00

When I use IPython along with the -wthread option, it spawns a python subprocess,

  • 0

When I use IPython along with the -wthread option, it spawns a python subprocess, which appears as a Mac OS X application.

My problem is that when I send commands to that application (for example plotting with matplotlib), the window is updated behind all my other windows. I would like to be able to call a python command to switch this python window to the front (I do that manually with ⌘-tab, but I have to find the python application first, and there might be several ones).

Is there a python script to detect which application IPython has spawned, and how to then automatically switch to it in OS X?

(I’m stating the problem in OS X, but the issue should be similar on other systems).

Edit: let me break this down in two problems:

  1. how to know which Mac OS X application python is running in? (probably possible with some IPython witchery)
  2. how to tell Mac OS X to put the focus on that application? (maybe using applescript)
  • 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-05-13T18:18:15+00:00Added an answer on May 13, 2026 at 6:18 pm

    Here is my full solution, with an IPython magic function.

    Install appscript (see this question about switching apps programmatically in OS X), and put the following code in a script called activate.py in your ~/.ipython folder.

    import appscript
    import sys
    appscript.app(pid=int(sys.argv[1])).activate()
    

    Now, edit your ~/.ipython/ipy_user_conf.py configuration file and define the magic function:

    def wxactivate(self, arg):
       import wx
       pid = wx.GetProcessId()
       ip = self.api
       import os
       here = os.path.dirname(__file__)
       import subprocess
       subprocess.Popen([os.path.join(here, 'activate.py'), str(pid)])
    

    Now you just have to register this magic IPython function by putting the following somewhere in that same configuration file:

    ip.expose_magic('wxactivate', wxactivate)
    

    Now, after you run IPython -wthread, you can call %wxactivate and you will switch to the corresponding Python application!

    (note that the reason why one has to run the call to appscript’s activate() in another process in not clear to me; it may have to do with some threading problem… any explanation would be appreciatated)

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

Sidebar

Ask A Question

Stats

  • Questions 377k
  • Answers 377k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You item template looks wrong It should be <div id="name_links">… May 14, 2026 at 8:53 pm
  • Editorial Team
    Editorial Team added an answer The server edition of Ubuntu is really intended to be… May 14, 2026 at 8:53 pm
  • Editorial Team
    Editorial Team added an answer Just as an update, I ended up using Word macros,… May 14, 2026 at 8:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.