Re: A thread import problem

Discussion in 'Python' started by Dieter Maurer, Jul 21, 2012.

  1. Bruce Sherwood <> writes:
    > ...
    > from visual import box, rate
    > b = box()
    > while True:
    > rate(100) # no more than 100 iterations per second
    > b.pos.x += .01
    >
    > This works because a GUI environment is invoked by the visual module
    > in a secondary thread (written mainly in C++, connected to Python by
    > Boost). The OpenGL rendering of the box in its current position is
    > driven by a 30-millisecond timer. This works fine with any environment
    > other than Mac Cocoa.
    >
    > However, the Mac Cocoa GUI environment and interact loop are required
    > to be the primary thread, so the challenge is to have the visual
    > module set up the Cocoa environment, with the user's program running
    > in a secondary thread. Any ideas?


    The usual approach to this situation is to invoke the user code via
    a callback from the UI main loop or invoke it explicitely
    after the UI system has been set up immediately before its main loop
    is called. Might look somehow like this:

    main thread:

    from thread import start_new_thread
    from visual import setup_gui, start_main_loop
    setup_gui() # sets up the GUI subsystem
    start_new_thread(lambda: __import__(<your module>), ())
    start_main_loop()
    Dieter Maurer, Jul 21, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Seefeld
    Replies:
    3
    Views:
    947
  2. per9000
    Replies:
    7
    Views:
    396
    Magnus Lycka
    Feb 27, 2006
  3. Bruce Sherwood

    A thread import problem

    Bruce Sherwood, Jul 19, 2012, in forum: Python
    Replies:
    0
    Views:
    148
    Bruce Sherwood
    Jul 19, 2012
  4. Dennis Lee Bieber

    Re: A thread import problem

    Dennis Lee Bieber, Jul 19, 2012, in forum: Python
    Replies:
    0
    Views:
    164
    Dennis Lee Bieber
    Jul 19, 2012
  5. Dieter Maurer

    Re: A thread import problem

    Dieter Maurer, Jul 19, 2012, in forum: Python
    Replies:
    0
    Views:
    136
    Dieter Maurer
    Jul 19, 2012
Loading...

Share This Page