kivy/kivy — Issue #372: UrlRequest during main app build() method
Author: willheger
Created: 2012-01-18 02:48:40+00:00
State: open

The issue presents when a UrlRequest is made in the main app's build method before the...

```
[ INFO ] [Base ] Start application main loop
```
...has displayed.

This is a tough issue to reproduce consistently and the conditions are very narrow. The size of the app seems to effect the start time of the main loop as well, so a 'toy' app might work where a larger app might not.

The requirements are:

* very small body -- the original problem occurred with the SocketIO handshake page served by node.js -- a one line GET
* very fast service -- the server was local

In every case, the server verified sending the body as shown in its logs. And inside the UrlRequest object, the internal event queue contained the 'progress' and 'success' events, they were just never triggered.

```python
class EventTest(App):
def success(self, event, msg):
print msg

#this version fails the most consistently, the naked urlrequest
def build(self):
UrlRequest("http://localhost/", self.success)
```

```python
class EventTest(App):
def success(self, event, msg):
print msg

def req(self, a):
UrlRequest("http://localhost/", self.success)

#wrap the UrlRequest in a Clock event usually fails on 0 sec timeouts
def build(self):
Clock.schedule_once(self.req, 0)
```

But simply setting the clock back to 5 seconds, and re-running:

```python
#the same request never fails on a 5 second timeout
def build(self):
Clock.schedule_once(self.req, 5)
```

Besides setting the event to execute later, "-1" was also used which seemed to work intermittently. Also unsuccessful were:

```
app.bind(on_start=self.req)
```

and

```
EventLoop.ensure_window()
UrlRequest("http://localhost/", self.success)
```