4 月 242024
 

Source: Python Program to Get Hostname

Overview

Python offers a wide range of networking-related applications. It is frequently used by developers as a means of communication with other users on your network. Hence, these communications require the hostname in Python. The hostname is the name that is provided to a device to identify it in a local network. Basically, by using the hostname, the machines can communicate within a network. In this article, we will learn about the Python get hostname function and various ways for the same.

Continue reading »
1 月 162024
 

Source: Python 以 ctypes 載入 DLL、SO 動態連結函式庫教學與範例

Python 的 ctypes 模組可以用來呼叫外部的函式庫,提供相容於 C 語言的資料型別,開發者可以透過這個模組直接呼叫 DLL 檔案(Windows 平台)或 SO 檔案(macOS 或 Linux 平台)中的函數。以下分別介紹 Windows 平台建立與使用 DLL 檔案、macOS 與 Linux 平台建立與使用 SO 檔案的步驟。

Continue reading »
12 月 212023
 

cpu stress:

from multiprocessing import Pool
from multiprocessing import cpu_count

def f(x):
    while True:
        x*x

if __name__ == '__main__':
    processes = cpu_count()
    print('utilizing %d cores\n' % processes)
    pool = Pool(processes)
    pool.map(f, range(processes))

memory stress:

# Eats about 1GB of memory
x = bytearray(1*1024*1024*1024)

Source:

Continue reading »
7 月 032023
 

Source: MicroPython umqtt 連線/斷線的的注意事項

MicroPython 提供有 umqtt 模組可以使用 MQTT 協定, 不過在 umqtt 裡面有再分為 simple 和 robust 模組, 這兩種模組功能基本相同, 但如果設計純訂閱端 (只收資料不送資料) 這樣的程式, 在使用上就必須多加留意。

Continue reading »