Problem wiht Kivy + MS Windows + multi processing - extra window popping up

381 views
Skip to first unread message

Brent Picasso

unread,
Nov 26, 2014, 4:28:24 PM11/26/14
to kivy-...@googlegroups.com
Hello,

I am experiencing a fundamental problem with Kivy and multi-processing on windows.  (1.8.0  / Python 2.7).  When I run the code below, i'm seeing an kivy window pop up when the sub-process is created. From my research, it seems to be tied to kivy being referenced before the sub process is created. The example to repro is is simple, listed below:

What can I do to use multiprocessing successfully with kivy?

Thank you very much.

========File mptest.py==============

from time import sleep
import multiprocessing
   
def the_sub_process():
    for x in range(0,10):
        print("sub process")
        sleep(1)

class Mptest(object):
    def __init__(self, **kwargs):
        self.start_connection_process()
        
    def start_connection_process(self):
        connection_process = multiprocessing.Process(target=the_sub_process)
        connection_process.start()


========File main.py==============

#!/usr/bin/python
__version__ = "1.0.0"
from multiprocessing import freeze_support
from mptest import Mptest
if __name__ == '__main__':
    freeze_support()
    Mptest().start_connection_process()


from kivy.uix.label import Label
#as soon as this reference to a kivy widget is enabled, multiple windows open up.
Label()

Brent Picasso

unread,
Nov 26, 2014, 4:43:00 PM11/26/14
to kivy-...@googlegroups.com
I think I'm getting further. Seems that my app somewhere has some kivy code not being guarded by the if __name__ == '__main__'

this example works, with only one window.




#!/usr/bin/python
__version__ = "1.0.0"

from multiprocessing import freeze_support
from mptest import Mptest

import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.uix.button import Button

class MyApp(App):
    def build(self):
        return Button(text='Hello World')

if __name__ == '__main__':
    freeze_support()
    Mptest().start_connection_process()
    MyApp().run()

Brent Picasso

unread,
Nov 26, 2014, 5:26:10 PM11/26/14
to kivy-...@googlegroups.com
So I have liberal use of Builder.load_file() which I believe is triggering this problem.  For example, the snippet below.

Where would an appropriate place be for loading this file - and making sure it's executed only once?

Thanks, 
Brent

=============================

Builder.load_file('iconbutton.kv')

class IconButton(Button):
    def __init__(self, **kwargs):
        super(IconButton, self).__init__(**kwargs)

class RoundedRect(BoxLayout):
    rect_color = ObjectProperty((0.5, 0.5, 0.5, 0.8))
    corners = ListProperty([0, 0, 0, 0])
    line_width = NumericProperty(1)
    resolution = NumericProperty(100)
=============================





--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/rT19mgfomHQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Brent Picasso
Technology for Race and Street

Brent Picasso

unread,
Nov 26, 2014, 6:11:00 PM11/26/14
to kivy-...@googlegroups.com
Fixed. I put all of the imports in my main.py in a guard block.  
Reply all
Reply to author
Forward
0 new messages