google-cloud-datalab


What is the best way to stop execution of a cell on a Google Datalab notebook?


I would like to halt the execution of a cell executing python commands on a Google Datalab notebook if certain conditions are met.
What is the preferred method to do this that doesn't affect the rest of the notebook?
if x:
quit()
Will crash the notebook.
One potential solution is to wrap your code in a function and use return to exit early.
def do_work():
stopExecution = True
if stopExecution:
return
print 'do not print'
do_work()
Another solution is to raise an exception:
stopExecution = True
if stopExecution:
raise Exception('Done')
print 'do not print'
A better solution is to use the if statement to allow code execution, rather than block it. For example,
if ShouldIContinueWorking():
doWork()
else:
print 'Done' # do nothing (preferred) or return from function

Related Links

Restore google cloud notebook after restart
Is it possible to set a static external IP address in Cloud Shell?
Menubar in datalab keeps vanishing
How do I attach a local ssd to a Datalab instance?
Is it possible to create a google cloud datalab instance not using datalab-network?
fail to create repository [datalab-notebooks] for Project
bigquery - current_date() inconsistent result?
Can I export to Google Sheets from Datalab?
Using bq command in datalab - credentials needed
Can I create kernel gateway endpoints in google cloud datalab?
Fastest way to read big amounts of data in Google Datalab?
Datalabs project not found
Datalab front get stuck when opening notebooks, and buttons aren't working
How can I programmatically give Cloud ML access to a bucket?
Running cloud datalab kernel on my own server?
How can I get the Cloud ML service account programmatically in Python?

Categories

HOME
xml
gridview
redux-form
rdbms
3d
hessian
grafana
google-cloud-functions
cq5
visual-studio-emulator
special-characters
pcl-crypto
text-mining
x-cart
favicon
lilypond
question2answer
ios10.2
gmock
maze
ms-access-web-app
outliers
firebase-analytics
datastax-enterprise-graph
ceylon
boost-asio
dotspatial
eviews
event-flow
recurring-events
kodi
glib
carriage-return
yowsup
roblox
video-capture
graphhopper
amazon-ses
cin
c9.io
watchface
claims
placeholder
photos
memory-mapping
jboss-4.2.x
cnc
hammer.js
user-defined-fields
launchctl
janus
flyout
polyline
stax
model-associations
ng-grid
clipboard.js
turbo-prolog
sklearn-pandas
beanstalk
aspen
concurrentmodification
ember-cli-rails
atoi
dulwich
canvg
google-refine
osc
zxspectrum
actionfilterattribute
ghcjs
punycode
entry-point
trdion2011
unix-socket
radiant
rfc5322
spring-3
pclzip
twisted.web
jsr286
floating-point-exceptions
rmdir
quotation-marks
cloudfiles
vs-android
drupal-fivestar
silverlight-oob
localizable.strings
fault-tolerance
great-circle

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App