Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Adventure Time with dev_appserver2

Adventure Time with dev_appserver2

Avatar for Dylan Vassallo

Dylan Vassallo

December 11, 2013
Tweet

More Decks by Dylan Vassallo

Other Decks in Programming

Transcript

  1. listen 127.0.0.1:80; ! root /Users/dylan/khan/webapp; ! location / { try_files

    $uri @proxy; } ! location @proxy { proxy_pass http://127.0.0.1:8080; }
  2. listen 127.0.0.1:80; ! root /Users/dylan/khan/webapp; ! location / { try_files

    $uri @proxy; } ! location @proxy { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $http_host; }
  3. Traceback (most recent call last): File “/.../google/appengine/api/taskqueue/taskqueue_stub.py”, line 1890, in

    ExecuteTask '0.1.0.2') File “/.../google/appengine/tools/devappserver2/dispatcher.py”, line 587, in add_request headers_dict['Host'], urlparse.urlsplit(relative_url).path) File “/.../google/appengine/tools/devappserver2/dispatcher.py”, line 653, in _resolve_target raise request_info.ModuleDoesNotExistError(hostname) ModuleDoesNotExistError: webapp.khanacademy.local
  4. commit ea3378f3eb3a9754aa0464dbe68bbcc3cef94c76 Author: Chris Klaiber <[email protected]> Date: Thu Sep 19

    17:38:45 2013 -0700 ! Reintroduce fsevents_file_watcher.py This patch makes fsevents_file_watcher the default again on Mac. It was removed in the 1.8.x SDK versions. To use the mtime_file_watcher instead, invoke "dev_appserver.py --use_mtime_file_watcher=yes" You will need pyobjc installed to use the fsevents file watcher. Running "pip install pyobjc" should do the trick. The old file watcher was resurrected from version control at https://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine It's easiest to apply this patch using `git am <this.patch` or `patch -p1 <this.patch` after having already applied watcher-skip-files.patch
  5. def _fsevents_callback(self, *unused_args): self._has_changes = True ! def _watch_changes(self): #

    Do the file watching in a thread to ensure that # FSEventStreamScheduleWithRunLoop and CFRunLoopRunInMode are called in the # same thread. ! # Each thread needs its own AutoreleasePool. pool = AppKit.NSAutoreleasePool.alloc().init() event_stream = FSEvents.FSEventStreamCreate( None, self._fsevents_callback, None, [self._directory], FSEvents.kFSEventStreamEventIdSinceNow, 1, # Seconds to wait to between received events. FSEvents.kFSEventStreamCreateFlagNone, ) ! FSEvents.FSEventStreamScheduleWithRunLoop(event_stream, FSEvents.CFRunLoopGetCurrent(), FSEvents.kCFRunLoopDefaultMode)
  6. def _fsevents_callback(self, *unused_args): self._has_changes = True ! def _watch_changes(self): #

    Do the file watching in a thread to ensure that # FSEventStreamScheduleWithRunLoop and CFRunLoopRunInMode are called in the # same thread. ! # Each thread needs its own AutoreleasePool. pool = AppKit.NSAutoreleasePool.alloc().init() event_stream = FSEvents.FSEventStreamCreate( None, self._fsevents_callback, None, [self._directory], FSEvents.kFSEventStreamEventIdSinceNow, 1, # Seconds to wait to between received events. # We're interested in per-file (not per-directory) events. FSEvents.kFSEventStreamCreateFlagFileEvents, ) ! FSEvents.FSEventStreamScheduleWithRunLoop(event_stream, FSEvents.CFRunLoopGetCurrent(), FSEvents.kCFRunLoopDefaultMode)
  7. def _fsevents_callback(self, stream_ref, client_call_back_info, num_events, event_paths, event_flags, event_ids): ! #

    There are other flags, but these ones specifically indicate that a single # file has changed in some way. change_flags = ( FSEvents.kFSEventStreamEventFlagItemCreated | FSEvents.kFSEventStreamEventFlagItemRemoved | FSEvents.kFSEventStreamEventFlagItemInodeMetaMod | FSEvents.kFSEventStreamEventFlagItemRenamed | FSEvents.kFSEventStreamEventFlagItemModified | FSEvents.kFSEventStreamEventFlagItemFinderInfoMod | FSEvents.kFSEventStreamEventFlagItemChangeOwner | FSEvents.kFSEventStreamEventFlagItemXattrMod) ! for path, flag in zip(event_paths, event_flags): ! # Ignore the event if it doesn't match any of the aforementioned flags. if not flag & change_flags: continue ! # Ignore the path if it is an ignored directory. if any(d in path for d in watcher_common._IGNORED_DIRS): continue ! # Ignore the path if it has an ignored file extension. if watcher_common.ignore_file(os.path.split(path)[1]): continue ! # We found a changed file that we want to trigger a reload. self._has_changes = True return