uliweb can bind tcp server?

17 views
Skip to first unread message

SeedSeek

unread,
Jan 7, 2016, 9:17:02 AM1/7/16
to Uliweb
想在uliweb 綁定一個普通tcp server ,使用uliweb ORM

有什麼方法可以做到?

limodou

unread,
Jan 7, 2016, 9:34:57 AM1/7/16
to uliweb
使用ORM和绑定tcp server有关系吗?

On Thu, Jan 7, 2016 at 10:17 PM, SeedSeek <frt5...@gmail.com> wrote:
想在uliweb 綁定一個普通tcp server ,使用uliweb ORM

有什麼方法可以做到?

--
-- ----
Project : https://github.com/limodou/uliweb
doc : http://limodou.github.com/uliweb-doc
---
You received this message because you are subscribed to the Google Groups "Uliweb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uliweb+un...@googlegroups.com.
To post to this group, send email to uli...@googlegroups.com.
Visit this group at https://groups.google.com/group/uliweb.
To view this discussion on the web visit https://groups.google.com/d/msgid/uliweb/c2944975-757f-44dc-b5e0-1f4fcd83d987%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: https://github.com/limodou/uliweb
My Blog: http://my.oschina.net/limodou

Chunlin Zhang

unread,
Jan 7, 2016, 9:59:45 AM1/7/16
to uli...@googlegroups.com
和web服务是不同的对吧?
那你需要和web服务在不同的线程或者进程中运行吗?

On Thu, Jan 7, 2016 at 10:17 PM, SeedSeek <frt5...@gmail.com> wrote:
想在uliweb 綁定一個普通tcp server ,使用uliweb ORM

有什麼方法可以做到?

--

cnidance

unread,
Jan 7, 2016, 10:01:24 AM1/7/16
to uli...@googlegroups.com
Chunlin Zhang 就像你說的那樣,你有經驗?


For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

Chunlin Zhang

unread,
Jan 7, 2016, 10:31:10 AM1/7/16
to uli...@googlegroups.com
我其实没有经验 只是大概知道你要做什么
不过为什么不直接用web api提供数据库服务呢 感觉那样更方便

cnidance

unread,
Jan 7, 2016, 11:12:19 AM1/7/16
to uli...@googlegroups.com
使用web api 延遲時間太長,需要快速做完。


For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

limodou

unread,
Jan 7, 2016, 7:50:46 PM1/7/16
to uliweb
把你的应用场景再说清晰一些。目前uliweb的ORM是可吧不在web环境下使用的,如批处理,只要在使用前先启动应用,如:

from uliweb import functions
from uliweb.manage import make_simple_application

app = make_simple_application(project_dir='.')
User = functions.get_model('user')


On Thu, Jan 7, 2016 at 11:01 PM, cnidance <frt5...@gmail.com> wrote:

For more options, visit https://groups.google.com/d/optout.



--

Chunlin Zhang

unread,
Jan 8, 2016, 4:12:24 AM1/8/16
to uli...@googlegroups.com
按limodou说的应该是可以的
另外开一个进程来做这个活

cnidance

unread,
Jan 8, 2016, 7:03:59 AM1/8/16
to uli...@googlegroups.com
apps/settings.ini 裡面有
[MIDDLEWARES]
transaction = 'uliweb.orm.middle_transaction.TransactionMiddle'
orm_notfound = 'uliweb.orm.middle_notfound.ORMNotfoundMiddle'

會報錯
  File "/home/other/uliweb_AIO/myproject/mydb/dbtracker/library/uliweb/manage.py", line 177, in make_simple_application
    dispatcher_kwargs=dispatcher_kwargs, reuse=reuse, pythonpath=pythonpath)
  File "/home/other/uliweb_AIO/myproject/mydb/dbtracker/library/uliweb/manage.py", line 117, in make_application
    **dispatcher_kwargs)
  File "/home/other/uliweb_AIO/myproject/mydb/dbtracker/library/uliweb/core/SimpleFrame.py", line 582, in __init__
    self.init(project_dir, apps_dir)
  File "/home/other/uliweb_AIO/myproject/mydb/dbtracker/library/uliweb/core/SimpleFrame.py", line 636, in init
    Dispatcher.middlewares = self.install_middlewares()
  File "/home/other/uliweb_AIO/myproject/mydb/dbtracker/library/uliweb/core/SimpleFrame.py", line 1243, in install_middlewares
    m = self._sort_middlewares(settings.get('MIDDLEWARES', {}).values())
  File "/home/other/uliweb_AIO/myproject/mydb/dbtracker/library/uliweb/core/SimpleFrame.py", line 1292, in _sort_middlewares
    cls = import_attr(middleware_path)
  File "/home/other/uliweb_AIO/myproject/mydb/dbtracker/library/uliweb/utils/common.py", line 48, in import_attr
    mod, f = import_mod_attr(func)
  File "/home/other/uliweb_AIO/myproject/mydb/dbtracker/library/uliweb/utils/common.py", line 35, in import_mod_attr
    mod = __import__(module, fromlist=['*'])
  File "/home/other/uliweb_AIO/myproject/mydb/lib/python2.7/site-packages/gevent-1.1rc1-py2.7-linux-x86_64.egg/gevent/builtins.py", line 58, in __import__
    result = _import(*args, **kwargs)
ImportError: No module named middle_transaction



For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

limodou

unread,
Jan 8, 2016, 8:07:51 AM1/8/16
to uliweb
这个是怎么运行的?


For more options, visit https://groups.google.com/d/optout.



--

cnidance

unread,
Jan 8, 2016, 9:39:26 AM1/8/16
to uli...@googlegroups.com
from uliweb import functions
from uliweb import manage
from uliweb.orm import *
#from uliweb.manage import make_simple_application
from uliweb.manage import make_application

path = os.path.dirname(os.path.abspath(__file__))
if path not in sys.path:
    sys.path.insert(0, path)
apps_dir = os.path.join(path, 'apps')

manage.call('uliweb syncdb')

#app = make_simple_application(project_dir='.')
application = make_application(apps_dir=apps_dir)

這樣跑起來的。



For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

limodou

unread,
Jan 8, 2016, 6:45:59 PM1/8/16
to uliweb
make_application调得晚了,把它放在from uliweb import manage之后,并且from uliweb.orm import *应该不需要吧


For more options, visit https://groups.google.com/d/optout.

cnidance

unread,
Jan 18, 2016, 9:58:56 PM1/18/16
to uli...@googlegroups.com
1. Linux 系統 使用UTC時間

2. apps/settings.ini
    TIME_ZONE = 'GMT +8'
     LOCAL_TIME_ZONE = 'GMT +0'

3. models.py
    time = Field(datetime.datetime, auto_now_add=True)

數據庫記錄的時間一樣是UTC時間,是不是設定有錯誤?




For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

Chunlin Zhang

unread,
Jan 18, 2016, 10:15:13 PM1/18/16
to uli...@googlegroups.com
我猜这个跟unicode一样的 内部都保存uincode(utf8) 然后根据情况转成各种字符
时间这个内部都用utc,然后根据配置给客户端的时候转成需要的时间?

cnidance

unread,
Jan 19, 2016, 12:16:09 AM1/19/16
to uli...@googlegroups.com
可能我沒說清楚

timezoe 的功能沒有被啟動?
ex: UTC時間為 20160119.011055 , 應存入GMT +8 時間 20160119.091055

uliweb 對數據庫的datetime 字段,是在讀出時間才做timezone轉換? 還是寫入數據庫就轉換好timezone了?





For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

limodou

unread,
Jan 19, 2016, 12:57:07 AM1/19/16
to uliweb
要将 uliweb.contrib.timezone app添加进去才可以生效


For more options, visit https://groups.google.com/d/optout.

SeedSeek

unread,
Jan 19, 2016, 1:17:53 AM1/19/16
to Uliweb
from uliweb.manage import make_application
path = os.path.dirname(os.path.abspath(__file__))
if path not in sys.path:
    sys.path.insert(0, path)
apps_dir = os.path.join(path, 'apps')
application = make_application(apps_dir=apps_dir)
from uliweb import functions
from uliweb import manage

manage.call('uliweb syncdb')
manage.call('uliweb dbinit')

這樣跑起來還是報錯
ImportError: No module named middle_transaction


limodou於 2016年1月9日星期六 UTC+8上午7時45分59秒寫道:

limodou

unread,
Jan 19, 2016, 8:45:07 AM1/19/16
to uliweb
是新工程还是老工程,另外uliweb的版本。因为orm的middlewares这块以前有点调整。


For more options, visit https://groups.google.com/d/optout.

cnidance

unread,
Jan 19, 2016, 11:10:07 AM1/19/16
to uli...@googlegroups.com
__version__ = '0.5b'

在TCPServer 上,使用Uliweb ORM。



For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

limodou

unread,
Jan 19, 2016, 7:41:16 PM1/19/16
to uliweb
有没有一个可以简单测试的包?


For more options, visit https://groups.google.com/d/optout.

SeedSeek

unread,
Feb 17, 2016, 3:24:48 AM2/17/16
to Uliweb
這是簡單的測試包

現在還會出現另一個錯誤
MySQL server has gone away



limodou於 2016年1月20日星期三 UTC+8上午8時41分16秒寫道:

limodou

unread,
Feb 17, 2016, 7:44:58 AM2/17/16
to uliweb
mysql gone away如果是因为长时间没有请求,可以在settings.ini中设置:

[ORM]
CONNECTION_ARGS = {'pool_recycle':7200}

pool_recycle表示连接池失效的时间,2个小时,只要比mysql的断开时间小就可以。
> https://groups.google.com/d/msgid/uliweb/37ca0cc9-2071-4810-a78a-1e6d97d3576c%40googlegroups.com.

cnidance

unread,
Feb 17, 2016, 8:42:59 PM2/17/16
to uli...@googlegroups.com
測試包裡面有設定,還是會報錯。

Traceback (most recent call last):
  File "/home/oth/uliweb/myproject/myOBD/OBDtracker/OBD_TCP.py", line 643, in handle
  File "/home/oth/uliweb/myproject/myOBD/OBDtracker/OBD_TCP.py", line 202, in _receiveBatch
  File "/home/oth/uliweb/myproject/myOBD/OBDtracker/OBD_TCP.py", line 268, in _receive
  File "library/uliweb/orm/__init__.py", line 3759, in save
    obj = do_(self.table.insert().values(**d), self.get_session())
  File "library/uliweb/orm/__init__.py", line 591, in do_
    result = conn.execute(query, *(args or ()))
  File "library/uliweb/orm/__init__.py", line 365, in execute
    return self.connection.execute(query, *args)
  File "build/bdist.linux-armv7l/egg/sqlalchemy/engine/base.py", line 914, in execute
    return meth(self, multiparams, params)
  File "build/bdist.linux-armv7l/egg/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "build/bdist.linux-armv7l/egg/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement
    compiled_sql, distilled_params
  File "build/bdist.linux-armv7l/egg/sqlalchemy/engine/base.py", line 1146, in _execute_context
    context)
  File "build/bdist.linux-armv7l/egg/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
    exc_info
  File "build/bdist.linux-armv7l/egg/sqlalchemy/util/compat.py", line 200, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "build/bdist.linux-armv7l/egg/sqlalchemy/engine/base.py", line 1139, in _execute_context
    context)
  File "build/bdist.linux-armv7l/egg/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
  File "build/bdist.linux-armv7l/egg/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "build/bdist.linux-armv7l/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (_mysql_exceptions.OperationalError) (2006, 'MySQL server has gone away') [SQL: u'INSERT INTO obdtrans (terminal_id, cmd_code, terminal_serial, paltform_serial, trans_code, threading, paltform_time, modified_time) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)'] [parameters: ('20485454502f', '4554', '32', '', u'474554202f20485454502f312e310d0a486f73743a203136332e31372e31332e3234', u'Thread-3', datetime.datetime(2016, 2, 17, 10, 55, 47, 618270, tzinfo=<tzinfo GMT +8>), datetime.datetime(2016, 2, 17, 10, 55, 47, 618386, tzinfo=<tzinfo GMT +8>))]



For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

limodou

unread,
Feb 18, 2016, 7:43:02 AM2/18/16
to uliweb

cnidance

unread,
Feb 19, 2016, 1:38:18 AM2/19/16
to uli...@googlegroups.com
touch views.py
增加一個空的檔案,也會報錯
Traceback (most recent call last):
  File "OBD_TCP.py", line 47, in <module>
    application = make_application(apps_dir=apps_dir)
  File "library/uliweb/manage.py", line 135, in make_application
    **dispatcher_kwargs)
  File "library/uliweb/core/SimpleFrame.py", line 582, in __init__
    self.init(project_dir, apps_dir)
  File "library/uliweb/core/SimpleFrame.py", line 636, in init
    Dispatcher.middlewares = self.install_middlewares()
  File "library/uliweb/core/SimpleFrame.py", line 1243, in install_middlewares
    m = self._sort_middlewares(settings.get('MIDDLEWARES', {}).values())
  File "library/uliweb/core/SimpleFrame.py", line 1292, in _sort_middlewares
    cls = import_attr(middleware_path)
  File "library/uliweb/utils/common.py", line 48, in import_attr
    mod, f = import_mod_attr(func)
  File "library/uliweb/utils/common.py", line 35, in import_mod_attr
    mod = __import__(module, fromlist=['*'])
ImportError: No module named middle_transaction

For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

limodou

unread,
Feb 19, 2016, 7:14:34 PM2/19/16
to uliweb
因为那两个middleware已经放到uliweb.contrib.orm中了,位置变了。而且transcation这个middle是缺省配置了,可以看uliweb/contrib/orm/settings.ini。所以这个可以不用配置。
> https://groups.google.com/d/msgid/uliweb/CAHLXMV8RF7FfDXgH6bGTBdQH_r3Ao4-Hjd8kks0CpxwiBvWGpA%40mail.gmail.com.

cnidance

unread,
Feb 19, 2016, 10:04:53 PM2/19/16
to uli...@googlegroups.com
原來是位置變更了。



另一個報錯。
在settings.ini 已經配置這樣了,還是會報錯。
[ORM]
CONNECTION_ARGS = {'pool_recycle':7200}

錯誤內容
OperationalError: (_mysql_exceptions.OperationalError) (2006, 'MySQL server has gone away')

報錯是因為沒有正常回收嗎?



For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

limodou

unread,
Feb 20, 2016, 4:47:15 AM2/20/16
to uliweb
我执行不了你的代码,不太清楚是什么原因。连接超时只是 mysql server has gone away
的一种情况,有些sql超出缓冲区大小好象也有这样的错误,比如一次提交太多的数据。
> https://groups.google.com/d/msgid/uliweb/CAHLXMV-CGbu4t2SxsBUgYAC8KwS7BrwzZCWvnc6ESmVFu5aMrQ%40mail.gmail.com.

cnidance

unread,
Feb 20, 2016, 7:38:43 AM2/20/16
to uli...@googlegroups.com
我修改了一些原本的代碼,可以執行。

我這邊測試是超時後的處理報錯,不是提交太多數據。


For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

limodou

unread,
Feb 21, 2016, 7:33:59 AM2/21/16
to uliweb

cnidance

unread,
Feb 21, 2016, 10:41:50 AM2/21/16
to uli...@googlegroups.com
ORM對MYSQL超時的回收機制,與list 模板有關係?


For more options, visit https://groups.google.com/d/optout.



--
~Ten ~

limodou

unread,
Feb 22, 2016, 8:49:22 AM2/22/16
to uliweb
Reply all
Reply to author
Forward
0 new messages