How can I use kbgetc in xv6 - xv6

I want use kbdgetc() in user mode.
I need to use it to program a vim-like software in xv6.
I try to use kernel mode, but I totally don't know how to do it.

I guess that you want some non-buffering reading on fd 0?
To achieve this behavior, you can modify consoleintr function that is responsible of it.
First add some variable internal to the kernel to disable or not buffering.
Lets call it non_buffering and set its default values to 0.
Then add a system call to change this value (or modify an existing, as you want)
Change consoleintr this way (modification is line 221):
191 void
192 consoleintr(int (*getc)(void))
193 {
194 int c, doprocdump = 0;
195
196 acquire(&cons.lock);
197 while((c = getc()) >= 0){
198 switch(c){
....
216 default:
217 if(c != 0 && input.e-input.r < INPUT_BUF){
218 c = (c == '\r') ? '\n' : c;
219 input.buf[input.e++ % INPUT_BUF] = c;
220 consputc(c);
/* NON_BUFFERING added here */
221 if(non_buffering || c == '\n' || c == C('D') || input.e == input.r+INPUT_BUF){
222 input.w = input.e;
223 wakeup(&input.r);
224 }
225 }
226 break;
227 }
228 }
229 release(&cons.lock);
230 if(doprocdump) {
231 procdump(); // now call procdump() wo. cons.lock held
232 }
233 }

Related

How to solve 1064 error PyMySQL in Jupyter notebook?

I am using PyMySQLto create a simple table as a practice, but I can't create the table and getting this error: "ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax"
Can anyone point my mistake?
The code:
# CREATE TABLE
# open connection
connection = pymysql.connect(cnx['host'],cnx['username'],cnx['password'],cnx['db'])
# open cursor
cursor = connection.cursor()
# query for creating table
create_table = """
CREATE TABLE classroom (
student_id INTEGER PRIMARY KEY,
name VARCHAR(20),
gender CMAR(1),
physics_marks INTEGER,
chemistry_marks INTEGER,
mathematics_marks INTEGER
);"""
# execute query
cursor.execute (create_table)
# commit changes
connection.commit()
# close connection
connection.close()
The error:
---------------------------------------------------------------------------
ProgrammingError Traceback (most recent call last)
<ipython-input-34-358e0fa696d2> in <module>
15 );"""
16 # execute query
---> 17 cursor.execute (create_table)
18 # commit changes
19 connection.commit()
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\cursors.py in execute(self, query, args)
168 query = self.mogrify(query, args)
169
--> 170 result = self._query(query)
171 self._executed = query
172 return result
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\cursors.py in _query(self, q)
326 self._last_executed = q
327 self._clear_result()
--> 328 conn.query(q)
329 self._do_get_result()
330 return self.rowcount
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\connections.py in query(self, sql, unbuffered)
515 sql = sql.encode(self.encoding, 'surrogateescape')
516 self._execute_command(COMMAND.COM_QUERY, sql)
--> 517 self._affected_rows = self._read_query_result(unbuffered=unbuffered)
518 return self._affected_rows
519
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\connections.py in _read_query_result(self, unbuffered)
730 else:
731 result = MySQLResult(self)
--> 732 result.read()
733 self._result = result
734 if result.server_status is not None:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\connections.py in read(self)
1073 def read(self):
1074 try:
-> 1075 first_packet = self.connection._read_packet()
1076
1077 if first_packet.is_ok_packet():
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\connections.py in _read_packet(self, packet_type)
682
683 packet = packet_type(buff, self.encoding)
--> 684 packet.check_error()
685 return packet
686
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\protocol.py in check_error(self)
218 errno = self.read_uint16()
219 if DEBUG: print("errno =", errno)
--> 220 err.raise_mysql_exception(self._data)
221
222 def dump(self):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\err.py in raise_mysql_exception(data)
107 errval = data[3:].decode('utf-8', 'replace')
108 errorclass = error_map.get(errno, InternalError)
--> 109 raise errorclass(errno, errval)
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CMAR(1),\n physics_marks INTEGER,\n chemistr' at line 4")
Been a while since I have played with MySQL with python... Looks like some of the table field keys are incorrect (From what I'm used to seeing). Maybe try this and see how you go.
create_table = """
CREATE TABLE classroom (
student_id INT(11) AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(20) NOT NULL,
gender CHAR(1) NOT NULL,
physics_marks INT(4) NOT NULL,
chemistry_marks INT(4) NOT NULL,
mathematics_marks INT(4) NOT NULL,
);"""

UnboundLocalError: local variable 'key_schema' referenced before assignment

Im trying to integrate DAX with Pynamodb(working on an existing pull request). While testing the batch write method from aws DAX sdk I'm facing the below issue. Any help is appreciated.
/.virtualenvs/PynamoDB/lib/python2.7/site-packages/amazondax/DaxClient.pyc in batch_write_item(self, **kwargs)
98 Stubs.write_batchWriteItem_116217951_1(request, tube)
99
--> 100 result = self._decode_result('BatchWriteItem', request, Assemblers.batchWriteItem_116217951_1, tube)
101 result = self._resolve_attribute_values(result, tube)
102 return result
/.virtualenvs/PynamoDB/lib/python2.7/site-packages/amazondax/DaxClient.pyc in _decode_result(self, operation_name, request, assembler, tube)
223 if status == DaxClient.SUCCESS:
224 tube.skip() # Throw away the empty error header
--> 225 return assembler(request, tube)
226 else:
227 return self._handle_error(operation_name, tube)
/.virtualenvs/PynamoDB/lib/python2.7/site-packages/amazondax/Assemblers.pyc in batchWriteItem_116217951_1(request, tube)
115
116 for _ in range(num_items, 0, -2):
--> 117 key = AttributeValueDecoder._decode_key_bytes(_dec, key_schema)
118 if _dec.try_decode_null():
119 # DeleteRequest
UnboundLocalError: local variable 'key_schema' referenced before assignment
This is a known issue that I hope to have a fix out for shortly.
This is fixed in version 1.0.4 of the DAX Python client.

AttributeError: 'datetime.timedelta' object has no attribute '_get_object_id' : pyspark

I'm trying to modify date column.
Code is below:
sample = sample.withColumn('next_date', when(sample.next_date.isNull(), (sample['next_date'] + timedelta(days=1))).otherwise(sample['next_date']))
Its giving me following error:
AttributeError Traceback (most recent call last)
<ipython-input-127-dd09f90d8a49> in <module>()
6 sample = sample.withColumn('next_date', lead('date').over(windowSpecs))
7
----> 8 sample = sample.withColumn('next_date', when(sample.next_date.isNull(), (sample['next_date'] + timedelta(days=1))).otherwise(sample['next_date']))
9
10 sample = sample.withColumn('snapshot_date', lit(dt.datetime.now().strftime("%d-%m-%Y %H:%M")))
/usr/lib/spark/python/pyspark/sql/column.py in _(self, other)
108 def _(self, other):
109 jc = other._jc if isinstance(other, Column) else other
--> 110 njc = getattr(self._jc, name)(jc)
111 return Column(njc)
112 _.__doc__ = doc
/usr/lib/spark/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py in __call__(self, *args)
802
803 args_command = "".join(
--> 804 [get_command_part(arg, self.pool) for arg in new_args])
805
806 command = proto.CALL_COMMAND_NAME +\
/usr/lib/spark/python/lib/py4j-0.9-src.zip/py4j/protocol.py in get_command_part(parameter, python_proxy_pool)
276 command_part += ";" + interface
277 else:
--> 278 command_part = REFERENCE_TYPE + parameter._get_object_id()
279
280 command_part += "\n"
AttributeError: 'datetime.timedelta' object has no attribute '_get_object_id'
How do I resolve this?
Thanks in advance!
I know this is very old, but I solved the issue doing this:
sample = sample.withColumn('next_date', when(sample.next_date.isNull(), date_add(col('next_date'), 1).otherwise(sample['next_date']))
Hope this helps someone!

How to analyse a "Binding loop"

I have a Qt/QML application with a C++ model and a QML visualisation.
At run-time (start-up), I get a warning
QML Item: Binding loop detected for property "xyz"
I see no obvious loop in my QML.
Can I enable more debugging to understand where this loop comes from? Other suggestions?
I usually do this by placing a breakpoint in the Qt code that prints the warning. For that, you need to have a Qt with debug symbols.
Searching for "Binding loop detected" in the Qt sources gives me QQmlAbstractBinding::printBindingLoopError(). Placing a breakpoint there will usually lead to a backtrace that gives a clear picture of the situation.
Update: David Edmundson has developed a little tool that displays a QML-only backtrace on binding loops, see his blog here. Under the hood is does exactly what is described here, only that it is nicely automated and wrapped in a Python script.
Example:
Rectangle {
id: parent
width: child.width + 1
height: child.height + 1
Rectangle {
id: child
anchors.fill: parent
}
}
Backtrace:
1 QQmlAbstractBinding::printBindingLoopError qqmlabstractbinding.cpp 178 0x7ffff6eb36da
2 QQmlBinding::update qqmlbinding.cpp 221 0x7ffff6eb9abe
3 QQmlBinding::update qqmlbinding_p.h 97 0x7ffff6eba354
4 QQmlBinding::expressionChanged qqmlbinding.cpp 260 0x7ffff6eb9e68
5 QQmlJavaScriptExpressionGuard_callback qqmljavascriptexpression.cpp 361 0x7ffff6eb223e
6 QQmlNotifier::emitNotify qqmlnotifier.cpp 94 0x7ffff6e9087a
7 QQmlData::signalEmitted qqmlengine.cpp 763 0x7ffff6e19a45
8 QMetaObject::activate qobject.cpp 3599 0x7ffff683655e
9 QMetaObject::activate qobject.cpp 3578 0x7ffff6836364
10 QQuickItem::widthChanged moc_qquickitem.cpp 1104 0x7ffff7a7ba49
11 QQuickItem::geometryChanged qquickitem.cpp 3533 0x7ffff7a6e9cd
12 QQuickItem::setSize qquickitem.cpp 6389 0x7ffff7a75f35
13 QQuickAnchorsPrivate::setItemSize qquickanchors.cpp 400 0x7ffff7a60d94
14 QQuickAnchorsPrivate::fillChanged qquickanchors.cpp 177 0x7ffff7a5fe0e
15 QQuickAnchorsPrivate::itemGeometryChanged qquickanchors.cpp 441 0x7ffff7a6106f
16 QQuickItem::geometryChanged qquickitem.cpp 3523 0x7ffff7a6e96c
17 QQuickItem::setWidth qquickitem.cpp 6091 0x7ffff7a74c1d
18 QQuickItem::qt_static_metacall moc_qquickitem.cpp 874 0x7ffff7a7b0dc
19 QQuickItem::qt_metacall moc_qquickitem.cpp 946 0x7ffff7a7b4d8
20 QQuickRectangle::qt_metacall moc_qquickrectangle_p.cpp 610 0x7ffff7c189c2
21 QMetaObject::metacall qmetaobject.cpp 296 0x7ffff680118b
22 QQmlPropertyPrivate::writeBinding qqmlproperty.cpp 1512 0x7ffff6e33ec3
23 QQmlBinding::update qqmlbinding.cpp 199 0x7ffff6eb992a
24 QQmlBinding::update qqmlbinding_p.h 97 0x7ffff6eba354
25 QQmlBinding::expressionChanged qqmlbinding.cpp 260 0x7ffff6eb9e68
26 QQmlJavaScriptExpressionGuard_callback qqmljavascriptexpression.cpp 361 0x7ffff6eb223e
27 QQmlNotifier::emitNotify qqmlnotifier.cpp 94 0x7ffff6e9087a
28 QQmlData::signalEmitted qqmlengine.cpp 763 0x7ffff6e19a45
29 QMetaObject::activate qobject.cpp 3599 0x7ffff683655e
30 QMetaObject::activate qobject.cpp 3578 0x7ffff6836364
31 QQuickItem::widthChanged moc_qquickitem.cpp 1104 0x7ffff7a7ba49
32 QQuickItem::geometryChanged qquickitem.cpp 3533 0x7ffff7a6e9cd
33 QQuickItem::setSize qquickitem.cpp 6389 0x7ffff7a75f35
34 QQuickAnchorsPrivate::setItemSize qquickanchors.cpp 400 0x7ffff7a60d94
35 QQuickAnchorsPrivate::fillChanged qquickanchors.cpp 177 0x7ffff7a5fe0e
36 QQuickAnchorsPrivate::update qquickanchors.cpp 431 0x7ffff7a60fc6
37 QQuickAnchorsPrivate::updateOnComplete qquickanchors.cpp 425 0x7ffff7a60f93
38 QQuickItem::componentComplete qquickitem.cpp 4593 0x7ffff7a70944
39 QQmlObjectCreator::finalize qqmlobjectcreator.cpp 1207 0x7ffff6ecab66
40 QQmlComponentPrivate::complete qqmlcomponent.cpp 928 0x7ffff6e38609
41 QQmlComponentPrivate::completeCreate qqmlcomponent.cpp 964 0x7ffff6e386ee
42 QQmlComponent::completeCreate qqmlcomponent.cpp 957 0x7ffff6e386a0
43 QQmlComponent::create qqmlcomponent.cpp 791 0x7ffff6e37edd
44 QQuickView::continueExecute qquickview.cpp 476 0x7ffff7b720d4
45 QQuickViewPrivate::execute qquickview.cpp 124 0x7ffff7b7101f
46 QQuickView::setSource qquickview.cpp 253 0x7ffff7b71426
47 main main.cpp 24 0x4033e4
In the backtrace, one can see that the anchors.fill anchor for the child item is calculated when loading the file (frame 35, 36). That causes the child item's width to change (frame 31), which causes a binding update (frame 25) for a binding on the "width" property (frame 17) on the parent item. That in turn forces a recalculation of the child anchors (frame 14), which changes the child's width (frame 10), which updates a binding (frame 4). That is the same binding that was already being updated in frame 25, hence a binding loop exists. One can see that the this pointer in frame 25 and frame 4 are the same, i.e. the same binding is updated recursively.
Thanks much for the receipt however it did not help me. In case somebody will need it, adding another possible solution. I was getting binding loops in ListView trying to set all items width and list width to item max value:
ListView {
implicitWidth: contentItem.childrenRect.width
delegate: listItem
}
Item {
id: listItem
width: Math.max(internalWidth, listView.implicitWidth)
}
Binding loop error appeared on items count update but not every time - only on some batch binding updates, while the is no actual binding loop. Was able to solve the issue by moving binding expression to Binding QML Type and adding delayed property to it:
Item { // Item causing binding loop
Binding on item_property_causing_loop {
value: <binding_expression>
when: <when_expression> // Optional however could also help
delayed: true // Prevent intermediary values from being assigned
}
}
So in my case it is:
Item { // Item causing binding loop
id: listItem
Binding on width {
value: Math.max(internalWidth, listView.implicitWidth)
when: index >= 0 // Optional however could also help
delayed: true // Prevent intermediary values from being assigned
}
}

Awk script for substracting from the above field

Hi I have my input file with one field:
30
58
266
274
296
322
331
I need the output to be the difference of 2nd and 1st rows(58-30=28) and 3rd and 2nd rows(266-58=208) and so on.
my output should look like below:
30 30
58 28
266 208
274 8
any help please?
data=`cat file | xargs`
echo $data | awk '{a=0; for(i=1; i<=NF;i++) { print $i, $i-a; a=$i}}'
30 30
58 28
266 208
274 8
296 22
322 26
331 9
Update upon comment Without cat/xargs:
awk '{printf "%d %d\n", $1, $1-a; a=$1;}' file
You don't actually need the for loop from Khachick's answer as Awk will go through all the rows anyway. Simpler is:
cat file | awk '{ BEGIN { a=0 }; { print $1, $1-a; a=$1 }'
However it is also possible to skip the first row that you don't really want by initialising a variable in the BEGIN block and not doing the print if the variable is so initialised before changing its value. Sort of like:
BEGIN { started=0 }; { if(0 == started) { started = 1 } else { print $1, $1-a } }

Resources