<commit_before>__version__ = '0.1'

from kivy.app import App
from kivy.lang import Builder
from kivy.lib import osc
from kivy.clock import Clock
from kivy.utils import platform
platform = platform()

kv = '''
BoxLayout:
    orientation: 'vertical'
    BoxLayout:
        size_hint_y: None
        height: 30
        Button:
            text: 'start service'
            on_press: app.stop_service()
        Button:
            text: 'stop service'
            on_press: app.stop_service()

    ScrollView:
        Label:
            id: label
            size_hint_y: None
            height: self.texture_size[1]
            text_size: self.size[0], None

    BoxLayout:
        size_hint_y: None
        height: 30
        Button:
            text: 'ping'
            on_press: app.send()
        Button:
            text: 'clear'
            on_press: label.text = ''
        Label:
            id: date

'''


class ClientServerApp(App):
    def build(self):
        self.service = None
        self.start_service()
        osc.init()
        oscid = osc.listen(port=3002)
        osc.bind(oscid, self.display_message, '/message')
        osc.bind(oscid, self.date, '/date')
        Clock.schedule_interval(lambda *x: osc.readQueue(oscid), 0)
        return Builder.load_string(kv)

    def start_service(self):
        if platform == 'android':
            from android.service import AndroidService
            service = AndroidService('my pong service', 'running')
            service.start('')
            self.service = service

    def stop_service(self):
        if self.service:
            self.service.stop()
            self.service = None

    def send(self, *args):
        osc.sendMsg('/ping', [], port=3000)

    def display_message(self, message, *args):
        self.root.ids.label.text += '%s\n' % message[2]

    def date(self, message, *args):
        self.root.ids.date.text = message[2]


if __name__ == '__main__':
    ClientServerApp().run()<commit_msg>fix service starting and race-conditions<commit_after>__version__ = '0.1'

from kivy.app import App
from kivy.lang import Builder
from kivy.lib import osc
from kivy.clock import Clock
from kivy.utils import platform
platform = platform()

kv = '''
BoxLayout:
    orientation: 'vertical'
    BoxLayout:
        size_hint_y: None
        height: '30sp'
        Button:
            text: 'start service'
            on_press: app.start_service()
        Button:
            text: 'stop service'
            on_press: app.stop_service()

    ScrollView:
        Label:
            id: label
            size_hint_y: None
            height: self.texture_size[1]
            text_size: self.size[0], None

    BoxLayout:
        size_hint_y: None
        height: '30sp'
        Button:
            text: 'ping'
            on_press: app.send()
        Button:
            text: 'clear'
            on_press: label.text = ''
        Label:
            id: date

'''


class ClientServerApp(App):
    def build(self):
        self.service = None
        self.start_service()
        osc.init()
        oscid = osc.listen(port=3002)
        osc.bind(oscid, self.display_message, '/message')
        osc.bind(oscid, self.date, '/date')
        Clock.schedule_interval(lambda *x: osc.readQueue(oscid), 0)
        self.root = Builder.load_string(kv)
        return self.root

    def start_service(self):
        if platform == 'android':
            from android import AndroidService
            service = AndroidService('my pong service', 'running')
            service.start('service started')
            self.service = service

    def stop_service(self):
        if self.service:
            self.service.stop()
            self.service = None

    def send(self, *args):
        osc.sendMsg('/ping', [], port=3000)

    def display_message(self, message, *args):
        if self.root:
            self.root.ids.label.text += '%s\n' % message[2]

    def date(self, message, *args):
        if self.root:
            self.root.ids.date.text = message[2]


if __name__ == '__main__':
    ClientServerApp().run()
{'fraction_non_alphanumeric': 0.11132860288720332, 'fraction_numerical': 0.009297773427942257, 'mean_word_length': 1.9304659498207886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3028351', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1211, 'n_words': 294}