|
| 1 | +""" |
| 2 | +Function: |
| 3 | +_thread module contains features related to thread operations, and provides methods for creating and deleting threads, and interfaces related to mutex and semaphore. |
| 4 | +
|
| 5 | +Descriptions taken from: |
| 6 | +https://python.quectel.com/doc/API_reference/en/stdlib/_thread.html |
| 7 | +""" |
| 8 | + |
| 9 | + |
| 10 | +def get_ident(): |
| 11 | + """Requires the current thread number. |
| 12 | +
|
| 13 | + @return: Returns the current thread number. |
| 14 | + """ |
| 15 | + |
| 16 | +def stack_size(size): |
| 17 | + """ set thread stack size |
| 18 | + Setting or getting the stack size which is used to create a thread (Unit: byte) depends on whether size is provided. The stack size is 8448 bytes by default, with a minimum of 8192 bytes. |
| 19 | +
|
| 20 | + @param size: Sets the stack size which is used to create a thread when size is provided. |
| 21 | + @return: Returns the stack size which is used to create a thread when size is not provided. |
| 22 | + """ |
| 23 | + |
| 24 | +def start_new_thread(function, args): |
| 25 | + """create new thread. |
| 26 | + Creates a thread to receive the executing function and the parameter of the executed function, and passes an empty tuple if function has no parameters. |
| 27 | +
|
| 28 | + @param function: The executing function of the thread. |
| 29 | + @param args: The parameter of the executing function of the thread, which passes an empty tuple when the function has no parameters. |
| 30 | + @return: Returns the ID of the created thread. |
| 31 | + """ |
| 32 | + |
| 33 | +def threadIsRunning(thread_id): |
| 34 | + """check if thread is running or not according to `thread_id`. |
| 35 | +
|
| 36 | + :param thread_id: thread ident, a int type. |
| 37 | + :return: True or False |
| 38 | + """ |
| 39 | + |
| 40 | +def stop_thread(thread_id): |
| 41 | + """Deletes a thread. The main thread cannot be deleted. |
| 42 | +
|
| 43 | + @param thread_id: The returned ID when the thread is created. If the value is 0, the current thread is deleted. |
| 44 | + @return: None |
| 45 | + """ |
| 46 | + |
| 47 | +def get_heap_size(): |
| 48 | + """Gets the remaining size of heap in the system. |
| 49 | +
|
| 50 | + @return: Returns the remaining size of heap in the system. (Unit: byte) |
| 51 | + """ |
| 52 | + |
| 53 | +class Lock(object): |
| 54 | + |
| 55 | + def acquire(self): |
| 56 | + """Acquires the lock. |
| 57 | +
|
| 58 | + @return: True-Successful execution; False-Failed execution. |
| 59 | + """ |
| 60 | + |
| 61 | + def release(self): |
| 62 | + """Releases the lock.""" |
| 63 | + |
| 64 | + def locked(self): |
| 65 | + """Returns the status of the lock. |
| 66 | +
|
| 67 | + @return: True indicates the status of the lock has been required by some thread; False indicates the status of the lock has not been required by the thread. |
| 68 | + """ |
| 69 | + |
| 70 | +def allocate_lock() -> Lock: |
| 71 | + """Creates a mutex object. |
| 72 | +
|
| 73 | + @return: Returns the created mutex object. |
| 74 | + """ |
| 75 | + |
| 76 | +def delete_lock(lock): |
| 77 | + """Deletes the created mutex. |
| 78 | +
|
| 79 | + @param lock: The returned mutex object when the mutex is created. |
| 80 | + @return: None |
| 81 | + """ |
| 82 | + |
| 83 | +class Semphore(object): |
| 84 | + |
| 85 | + |
| 86 | + def acquire(self): |
| 87 | + """Acquires the semphore.""" |
| 88 | + |
| 89 | + def release(self): |
| 90 | + """Releases the semphore.""" |
| 91 | + |
| 92 | + def getCnt(self): |
| 93 | + """Gets the maximum value of the semaphore count and the current remaining count value. |
| 94 | +
|
| 95 | + @return: (maxCnt, curCnt)-tuple: maxCnt is the maximum count value, and curCnt is the current remaining count value. |
| 96 | + """ |
| 97 | + |
| 98 | +def allocate_semphore(initcount) -> Semphore: |
| 99 | + """Creates a semphore object. |
| 100 | +
|
| 101 | + @param initcount: The initial count value and also the maximum value of the semaphore. |
| 102 | + @return: Returns the created semphore object. |
| 103 | + """ |
| 104 | + |
| 105 | +def delete_semphore(semphore): |
| 106 | + """Deletes the created semphore. |
| 107 | +
|
| 108 | + @param semphore: The returned semphore object when the semphore is created. |
| 109 | + @return: None |
| 110 | + """ |
0 commit comments